TypeORM:SyntaxError:创建迁移时,无法在模块外部使用import语句

时间:2020-07-23 08:53:30

标签: typescript next.js typeorm

在我的NextJS打字稿项目中设置TypeORM时遇到一个问题,当我尝试从我的实体创建迁移时出现以下错误:SyntaxError: Cannot use import statement outside a module

1 个答案:

答案 0 :(得分:0)

解决方案是更新我的package.json并为ts节点创建tsconfig。

"typeorm:local": "yarn local ./node_modules/typeorm/cli.js",
"local": "DOTENV_CONFIG_PATH=./.env.local TS_NODE_PROJECT=tsconfig.ts-node.json TS_NODE_TRANSPILE_ONLY=true ts-node -r dotenv/config"
"g:migration": "yarn typeorm:local migration:generate -n",
"g:entity": "yarn typeorm:local entity:create -n",

tsconfig看起来像这样:

{
    "extends": "./tsconfig.json",
    "compilerOptions": { "module": "commonjs" }
}

如果您使用的是模块:commonjs,则无需进行此更改。