expo config plugin use import instead of require

15 Views Asked by At

I want to develop a custom plugin for my expo app to make some changes to my MainActivity file on Android.

I saw some examples in the documentation where the plugin was written using import/export, however that does not seem to work for me.

I am getting the following error:

import { ConfigPlugin, withDangerousMod } from "expo/config-plugins";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)
    at Module._compile (node:internal/modules/cjs/loader:1340:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at requirePluginFile (<path>/node_modules/@expo/config-plugins/build/utils/plugin-resolver.js:214:12)
    at resolveConfigPluginFunctionWithInfo (<path>/node_modules/@expo/config-plugins/build/utils/plugin-resolver.js:155:14)

I change the code to use require, however that degrades the DX since I can't import types and I lose the benefits of ts.

0

There are 0 best solutions below