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

SyntaxError: Cannot use import statement outside a module #343

Open
fraywing opened this issue Jan 21, 2020 · 3 comments
Open

SyntaxError: Cannot use import statement outside a module #343

fraywing opened this issue Jan 21, 2020 · 3 comments

Comments

@fraywing
Copy link

Expected behavior

Allow importing of ESM modules within the require-all module import happens.

Actual behavior

When importing an ESM module using babel, if that module has another ESM module inside it, we get this error (which ultimately comes from require-all):

import { arrayToObject } from '../utils/arrayUtils';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1055:16)
    at Module._compile (internal/modules/cjs/loader.js:1103:27)
    at Module._compile (/Users/austin/Dev/RupieNetwork/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:1159:10)
    at Object.newLoader [as .js] (/Users/austin/Dev/RupieNetwork/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:988:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1028:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/Users/austin/Dev/RupieNetwork/src/admin/models/gig.js:1:1)
    at Module._compile (internal/modules/cjs/loader.js:1139:30)
    at Module._compile (/Users/austin/Dev/RupieNetwork/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:1159:10)
    at Object.newLoader [as .js] (/Users/austin/Dev/RupieNetwork/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:988:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1028:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at /Users/austin/Dev/RupieNetwork/node_modules/require-all/index.js:56:46
    at Array.forEach (<anonymous>)
    at requireAll (/Users/austin/Dev/RupieNetwork/node_modules/require-all/index.js:34:9)
    at requireAllModels (/Users/austin/Dev/RupieNetwork/node_modules/forest-express/dist/index.js:95:7)
    at buildSchema (/Users/austin/Dev/RupieNetwork/node_modules/forest-express/dist/index.js:130:10)
    at Object.exports.init (/Users/austin/Dev/RupieNetwork/node_modules/forest-express/dist/index.js:232:3)
    at Object.init (/Users/austin/Dev/RupieNetwork/node_modules/forest-express-sequelize/dist/index.js:219:20)
    at new module.exports (/Users/austin/Dev/RupieNetwork/src/admin/middlewares/forestadmin.js:11:17)
    at resolve (/Users/austin/Dev/RupieNetwork/src/admin/app.js:62:24)
    at /Users/austin/Dev/RupieNetwork/node_modules/require-all/index.js:56:38
    at Array.forEach (<anonymous>)
    at requireAll (/Users/austin/Dev/RupieNetwork/node_modules/require-all/index.js:34:9)
    at /Users/austin/Dev/RupieNetwork/src/admin/app.js:59:3
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/austin/Dev/RupieNetwork/src/admin/app.js:14:103)
    at _next (/Users/austin/Dev/RupieNetwork/src/admin/app.js:16:194)

Failure Logs

See above

Context

Importing ESM modules that contain nested ESM modules from within sequelize-express.

  • Package Version: ^5.6.0
  • Express Version: ~4.17.1
@fraywing
Copy link
Author

Oh, and I'm using Node 13 -- which might have something to do with it?

@fraywing
Copy link
Author

looks like PM2 had to release a fix similar: Unitech/pm2#4540

@arnaudbesnier
Copy link
Member

Hi @fraywing, apologies for the late answer.
I apparently have the same issue using node v12.13.0.

It looks like Node.js does not natively support this syntax yet:

I guess you can pick one of those workaround, or continue to use CommonJS (as done by default in admin backend generated by the Lumber CLI).

Let me know if it helps.

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

No branches or pull requests

2 participants