SyntaxError: Cannot use import statement outside a module

JakubKoralewski
0
JakubKoralewski
commented a year ago

Version

v3.2.4

Steps to reproduce

  1. Deploy this branch to Netlify: https://github.com/JakubKoralewski/mireks/tree/feature/fixes

What is expected ?

to work

What is actually happening?

3:38:21 PM: > [email protected]1.0.0 generate /opt/build/repo
3:38:21 PM: > nuxt-ts generate && rimraf dist/**/*.js.map
3:38:24 PM:  FATAL  Cannot use import statement outside a module
3:38:24 PM:   import { resolve, join } from 'path'
3:38:24 PM:   ^^^^^^
3:38:24 PM:   SyntaxError: Cannot use import statement outside a module
3:38:24 PM:   at Object.compileFunction (vm.js:379:18)
3:38:24 PM:   at Generator.next (<anonymous>)
3:38:24 PM:    ╭───────────────────────────────────────────────────────────────╮
3:38:24 PM:    │                                                               │
3:38:24 PM:    │   ✖ Nuxt Fatal Error                                          │
3:38:24 PM:    │                                                               │
3:38:24 PM:    │   SyntaxError: Cannot use import statement outside a module   │
3:38:24 PM:    │                                                               │
3:38:24 PM:    ╰───────────────────────────────────────────────────────────────╯

Additional comments?

only happens on Netlify, works fine on my machine :/ node version is the same, npm version is the same, tried deleting package-lock and node-modules and reinstalling didnt help

both netlify and my machine have NODE_ENV set to development, and actually a sidenote I don't understand why Sentry logging is enabled on Netlify even though in the config it states it should be disabled when development is set on NODE_ENV and Netlify says by default it is development and I dont change it manually so I don't know why that works

Happened after I migrated from nuxt 2.0.0 to 2.11.0 and @nuxtjs/sentry from 3.0.0 to 3.2.4.

Pull request with all the changes available here.

bug
0
rchl
2.3k
rchl
commented a year ago

Interestingly, I saw that issue myself after upgrading to latest version of this module. Deleting node_modules fixed it for me though. Maybe netlify has some "too-effective" cache. But then I don't understand how it would happen in the first place…

I'll try to reproduce this on my repos again.

0
rchl
2.3k
rchl
commented a year ago

BTW. The fact that it's disabled doesn't prevent the module's code from being parsed and that is what is causing the issue.

0
JakubKoralewski
0
JakubKoralewski
commented a year ago

It's very weird. When I delete node_modules, commit, force push and build I got an error about no typescript module, then I fixed it, pushed and am back to square one with the same error.

I restarted the build that failed last time with force clean and not it seems to work…
Now of to work on a different (unrelated) error…

Feel free to close

0
uiuifree
0
uiuifree
commented a year ago

I upgraded node.js from v12.13.0 to v12.16.0.
I get same error.

0
rchl
2.3k
rchl
commented a year ago

rm -rf node_modules and npm install (or yarn) should help.

BTW. Things are bound to break if you update node version and not re-create node_modules directory.

(Still need to figure out how and why it happens.)

0
vedmaque
0
vedmaque
commented a year ago

Upgraded from v3.2.2 to v3.2.4, got this error.
Node v10.18.1

0
Informations
Bug ReportOpen
#c84 - Created a year ago