Typescript 无法使用“ts节点”在expo上运行脚本(react native)
这里没有 我有一些ReactJs项目,它在各个方面都运行得很好。 但最近我想把它做成monorepo,我选择了Expo来做这个工作 除了一些自定义脚本外,我可以使大多数代码正常工作。 它说Typescript 无法使用“ts节点”在expo上运行脚本(react native),typescript,react-native,expo,package.json,ts-node,Typescript,React Native,Expo,Package.json,Ts Node,这里没有 我有一些ReactJs项目,它在各个方面都运行得很好。 但最近我想把它做成monorepo,我选择了Expo来做这个工作 除了一些自定义脚本外,我可以使大多数代码正常工作。 它说SyntaxError:cannotuse use import statement out a module,导致此错误的代码行是node\u modules/expo/AppEntry.js,它位于package.json中的main参数中 这是完整的日志: $ ts-node -r tsconfig-pa
SyntaxError:cannotuse use import statement out a module
,导致此错误的代码行是node\u modules/expo/AppEntry.js
,它位于package.json
中的main
参数中
这是完整的日志:
$ 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.
不是每个脚本都会发生此错误,只是一些自定义脚本命令会发生此错误
我花了几个小时试图寻找解决方案,尝试了一系列方法,但都没有结果。T_ut
注意:如果我从package.json
中删除main
字段,所有错误都会消失
编辑:我创建了一个示例来重现此错误
{
"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"]
}