"Cannot use import statement outside a module"

I’ve replaced the entire project with the default project download, reset my .env, ran npm install twice, and repeatedly getting this error. I’ve researched it and found some things maybe related to babel transforms, but I’m not too interested in changing configs of this project as I’m not sure how it will affect things later.

Any tips would be appreciated:

> server@1.0.0 start /Users/johnsoct/Dropbox/Development/mongo_university/mflix
> nodemon -L ./index.js

[nodemon] 1.19.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node ./index.js`
/Users/johnsoct/Dropbox/Development/mongo_university/mflix/src/index.js:1
import app from "./server";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:891:16)
    at Module._compile (internal/modules/cjs/loader.js:941:27)
    at Module._compile (/Users/johnsoct/Dropbox/Development/mongo_university/mflix/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:1011:10)
    at Object.newLoader [as .js] (/Users/johnsoct/Dropbox/Development/mongo_university/mflix/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:822:32)
    at Function.Module._load (internal/modules/cjs/loader.js:730:14)
    at Module.require (internal/modules/cjs/loader.js:864:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/Users/johnsoct/Dropbox/Development/mongo_university/mflix/index.js:4:28)

Hi @Chris_17591,

Thanks for sharing all the information here. Did you try removing everything from node_modules directory as well? If not, can you try that again. And then run npm install.

If it is still not resolved, please share the following information to debug:

  • What OS you are working on?
  • What is the version of Node you are using?
  • If you have changed anything in package.json file, then please share that as well.

Kanika

Yes, each time I tried X solution, I removed the directory and re-installed.

OSX Catalina 10.15.1
Node: 13.0.1
I haven’t altered package.json, but I’ve deleted package-lock a few times to rebuild, and nada.

Make sure you are running the npm install command from mflix-js directory only. Meanwhile, I have forwarded the issue to the team and we are looking into it. :slight_smile:

This seems like an output when running npm start. Please share the output/screenshot when you run npm install.

Kanika

@Chris_17591 could you provide a listing of files, both hidden and not, in the top level directory of your project (ls -la)? Typically we see this error when there is a missing .babelrc file.

I’ve just downloaded the course handout, unzipped it, renamed dotenv_unix to .env and changed by MFLIX_DB_URI and verified it works.

1 Like

I’ll retry install only in that directory. Can’t recall if that was the case.

Also, where are we able to see the React files? I’m a frontend dev and would love to see what is rendering the frontend. I assume there’s a command to show and unpackaged all the frontend files?

07

I don’t see a .babelrc file.

Interesting! While we look into possible issues on our end, here are the contents of the .babelrc file that should be there.

{
  "presets": [
    "@babel/preset-env"
  ],
  "plugins": [
    "@babel/transform-runtime",
    "@babel/plugin-syntax-dynamic-import",
    "@babel/plugin-syntax-import-meta",
    "@babel/plugin-proposal-class-properties",
    "@babel/plugin-proposal-json-strings",
    [
      "@babel/plugin-proposal-decorators",
      {
        "legacy": true
      }
    ],
    "@babel/plugin-proposal-function-sent",
    "@babel/plugin-proposal-export-namespace-from",
    "@babel/plugin-proposal-numeric-separator",
    "@babel/plugin-proposal-throw-expressions",
    "@babel/plugin-proposal-export-default-from",
    "@babel/plugin-proposal-logical-assignment-operators",
    "@babel/plugin-proposal-optional-chaining",
    [
      "@babel/plugin-proposal-pipeline-operator",
      {
        "proposal": "minimal"
      }
    ],
    "@babel/plugin-proposal-nullish-coalescing-operator",
    "@babel/plugin-proposal-do-expressions"
  ]
}
1 Like

Will give it a try. I’ll probably have to take the class over again :smiley: Oh well, not in a huge rush.

That was the issue. Thank you for your time, seriously!

Do you know when this course will start again? Is it a week or two break between the next start date?

It starts every Tuesday. So, one is starting today 17:00 UTC :slight_smile:

Kanika