这是菜鸟。
我有一些ReactJs项目,可以在各个方面完美运行。 但是最近我想使其成为monorepo,因此我选择了Expo来完成这项工作。
除了一些自定义脚本之外,我可以使大部分代码工作。
它说SyntaxError: Cannot use import statement outside a module
,导致此错误的代码行是node_modules/expo/AppEntry.js
,位于main
的{{1}}参数中。
这是完整的日志:
package.json
这是$ ts-node -r tsconfig-paths/register --project scripts/helpers/tsconfig.json scripts/customScript.ts
/home/username/Workspace/project/node_modules/expo/AppEntry.js:1
import 'expo/build/Expo.fx';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1050:16)
at Module._compile (internal/modules/cjs/loader.js:1098:27)
at Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
at Object.require.extensions.<computed> [as .js] (/home/username/Workspace/project/node_modules/ts-node/src/index.ts:529:44)
at Module.load (internal/modules/cjs/loader.js:983:32)
at Function.Module._load (internal/modules/cjs/loader.js:891:14)
at Module.require (internal/modules/cjs/loader.js:1023:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/home/username/Workspace/project/scripts/helpers/customScript.ts:2:1)
at Module._compile (internal/modules/cjs/loader.js:1128:30)
error Command failed with exit code 1.
的内容:
scripts/helpers/tsconfig.json
并非每个脚本都发生此错误,只是一些自定义脚本命令。
我试图搜索解决方案达数小时之久,并尝试了一堆没有结果的方法。 T__T
注意:如果我从{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"jsx": "preserve",
"lib": ["dom", "esnext"],
"moduleResolution": "node",
"noEmit": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"target": "es5",
"allowJs": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"module": "commonjs",
"isolatedModules": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noImplicitThis": false
},
"exclude": ["node_modules"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}
中删除main
字段,所有错误都会消失。
编辑:我创建了一个示例来重现此错误,ts-node-next-expo