[Bug] SyntaxError: Unexpected token 'export'
See original GitHub issue- I’d be willing to submit the fix
Describe the bug
I have a Nuxt application with a library of @adonisjs/websocket-client, when I compile it with Nuxt it works but when I use to test my application using mochapack it runs into an error of: SyntaxError: Unexpected token ‘export’ here is the full error:
node_modules/@adonisjs/websocket-client/dist/Ws.es.js:2507
export default index;
^^^^^^
SyntaxError: Unexpected token 'export'
To Reproduce
- Create a nuxt app using
npx create-nuxt-app <app-name>
oryarn create nuxt-app <app-name>
- Then install
@adonisjs/websocket-client
- Import Ws from
@adonisjs/websocket-client
in pages/index.vue - Configure mochapack to be able to test Nuxt app here is a link to set it up: Setup for Vue and Mochapack
- Run test and the error will occur
Here is a more details result of the error:
➜ npm run test
> nuxt-mochapack@1.0.0 test .../nuxt-mochapack
> mochapack
WEBPACK Compiling...
[=========================] 100% (completed)
WEBPACK Compiled successfully in 756ms
MOCHA Testing...
RUNTIME EXCEPTION Exception occurred while loading your tests
.../nuxt-mochapack/node_modules/@adonisjs/websocket-client/dist/Ws.es.js:2507
export default index;
^^^^^^
SyntaxError: Unexpected token 'export'
at wrapSafe (internal/modules/cjs/loader.js:891:16)
at Module._compile (internal/modules/cjs/loader.js:941:27)
at Module._extensions..js (internal/modules/cjs/loader.js:1011:10)
at Object.module_1.default._extensions.<computed> [as .js] (.../nuxt-mochapack/node_modules/mochapack/src/util/registerRequireHook.ts:99:53)
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)
Environment if relevant (please complete the following information):
- OS: Ubuntu 20.04
- Node version: 13.0.1
- Mochapack version: ^1.1.13
- Webpack version: (Not sure what version Nuxt is using)
Additional context
Remove some information replaced them with ...
for brevity. I also tried the configuring my mochapack.config.js with esModule: false
options for file-loader
but that did not do the trick. Just some more information Nuxt uses webpack as well and it compiles and run the application without any issues, only when I try to run the test with mochapack.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Hi @larixer The change should be done outside of mochapack.
setup.js:
Alternative solution is to use
esm
:@quangkevin This software is an open-source community project and comes without any warranties, please read the last paragraph of its license: https://github.com/sysgears/mochapack/blob/master/LICENSE.md For the issue to be fixed someone, who is interested, should submit a pull request with the fix first, it is a first step that should be done, but not the last, the pull request should have satisfactory quality and pass all the tests, it should have good code quality, etc, etc