Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I am getting "Cannot use import statement outside a module" #64

Open
spmsupun opened this issue Jun 15, 2020 · 4 comments
Open

I am getting "Cannot use import statement outside a module" #64

spmsupun opened this issue Jun 15, 2020 · 4 comments

Comments

@spmsupun
Copy link

When I try to run migrate up it says 'Cannot use import statement outside a module'
image

@chris-aeviator
Copy link

using const User = require('../models/user.js') instead of import { User } from '../models/user' should solve your issue

@nickhingston
Copy link

The version of nodejs doesn't support EMCAScript modules
So either:

  • upgrade to node 14+
  • run with node --experimental-modules node 8.9.0 +
  • use require as Chris suggested
  • also, require('@babel/register') if you require files that use import

@danline
Copy link

danline commented Oct 12, 2021

I was struggling with this too. If you are using babel, you can add a script to packages.json and run the script using npm run migrate-up. Here is what you can add to your packages.json under "scripts" section: "migrate-up": "./node_modules/.bin/babel-node ./node_modules/.bin/migrate up". This will make sure that everything is transpiled before running the migrate up command.

"scripts": {
    "dev": "nodemon src/server.js --exec babel-node --presets env",
    "build": "babel src -d dist --source-maps inline --copy-files",
    "migrate-up": "./node_modules/.bin/babel-node ./node_modules/.bin/migrate up"
  },

@rizhk
Copy link

rizhk commented Jun 26, 2022

@danline it is not working, i tried the same and getting this
Screenshot 2022-06-26 at 4 28 06 PM
my node version is v16.15.0, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants