0

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 1

-1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.