I came across a problem when setting up TypeORM within my NextJS typescript project whereby i was getting the following error: SyntaxError: Cannot use import statement outside a module when trying to create migration from my entities.
1 Answer
The solution was to update my package.json and also create a tsconfig for ts-node.
"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",
The tsconfig looks like this:
{
"extends": "./tsconfig.json",
"compilerOptions": { "module": "commonjs" }
}
If you are using module: commonjs then you wont need to make this change.