You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
vue/cli 5 versions with webpack 5 are not compatible with default unit testing setup, unit tests cannot be executed as mochapack does not support webpack 5
#6412
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.
Unit tests can be executed after setting up a project with vue/cli 5.
What is actually happening?
The following error occurs:
> [email protected] test:unit C:\tmp\vue2-webpack5\hello-world
> vue-cli-service test:unit
[ ] 0% () WEBPACK Compiling...
[=========================] 98% (emitting)
WARNING Compiled with 2 warnings
warning in ./node_modules/mochapack/lib/entry.js
Invalid dependencies have been reported by plugins or loaders for this module. All reported dependencies need to be absolute paths.
Invalid dependencies may lead to broken watching and caching.
As best effort we try to convert all invalid values to absolute paths and converting globs into context dependencies, but this is deprecated behavior.
Loaders: Pass absolute paths to this.addDependency (existing files), this.addMissingDependency (not existing files), and this.addContextDependency (directories).
Plugins: Pass absolute paths to fileDependencies (existing files), missingDependencies (not existing files), and contextDependencies (directories).
Globs: They are not supported. Pass absolute path to the directory as context dependencies.
The following invalid values have been reported:
* "\"../../../tests/unit/example.spec.ts\""
warning
DefinePlugin
Conflicting values for 'process.env.NODE_ENV'
[=========================] 99% (done) WEBPACK Compiled with 2 warning(s)
Warning in ./node_modules/mochapack/lib/entry.js
Invalid dependencies have been reported by plugins or loaders for this module. All reported dependencies need to be absolute paths.
Invalid dependencies may lead to broken watching and caching.
As best effort we try to convert all invalid values to absolute paths and converting globs into context dependencies, but this is deprecated behavior.
Loaders: Pass absolute paths to this.addDependency (existing files), this.addMissingDependency (not existing files), and this.addContextDependency (directories).
Plugins: Pass absolute paths to fileDependencies (existing files), missingDependencies (not existing files), and contextDependencies (directories).
Globs: They are not supported. Pass absolute path to the directory as context dependencies.
The following invalid values have been reported:
* "\"../../../tests/unit/example.spec.ts\""
Warning
DefinePlugin
Conflicting values for 'process.env.NODE_ENV'
[=========================] 100% (completed)
(node:33832) [DEP_WEBPACK_DEPRECATION_ARRAY_TO_SET] DeprecationWarning: Compilation.modules was changed from Array to Set (using Array method 'reduce' is deprecated)
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:33832) [DEP_WEBPACK_MODULE_ID] DeprecationWarning: Module.id: Use new ChunkGraph API
Error: Module.id: There was no ChunkGraph assigned to the Module for backward-compat (Use the new API)
at C:\tmp\vue2-webpack5\hello-world\node_modules\webpack\lib\ChunkGraph.js:1482:12
at deprecated (internal/util.js:89:15)
at Function.getChunkGraphForModule (C:\tmp\vue2-webpack5\hello-world\node_modules\webpack\lib\ChunkGraph.js:1473:18)
at MakeNamespaceObjectRuntimeModule.get id [as id] (C:\tmp\vue2-webpack5\hello-world\node_modules\webpack\lib\Module.js:172:21)
at C:\tmp\vue2-webpack5\hello-world\node_modules\mochapack\src\webpack\util\getAffectedModuleIds.ts:43:51
at Array.reduce (<anonymous>)
at Set.set.<computed> [as reduce] (C:\tmp\vue2-webpack5\hello-world\node_modules\webpack\lib\util\deprecation.js:87:35)
at buildModuleMap (C:\tmp\vue2-webpack5\hello-world\node_modules\mochapack\src\webpack\util\getAffectedModuleIds.ts:42:29)
at Object.getAffectedModuleIds [as default] (C:\tmp\vue2-webpack5\hello-world\node_modules\mochapack\src\webpack\util\getAffectedModuleIds.ts:144:32)
at Object.getBuildStats [as default] (C:\tmp\vue2-webpack5\hello-world\node_modules\mochapack\src\webpack\util\getBuildStats.ts:20:47)
at TestRunner.prepareMocha (C:\tmp\vue2-webpack5\hello-world\node_modules\mochapack\src\runner\TestRunner.ts:76:49)
at C:\tmp\vue2-webpack5\hello-world\node_modules\mochapack\src\runner\TestRunner.ts:116:34
at C:\tmp\vue2-webpack5\hello-world\node_modules\mochapack\src\webpack\compiler\registerReadyCallback.ts:15:7
at Hook.eval [as callAsync] (eval at create (C:\tmp\vue2-webpack5\hello-world\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:62:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (C:\tmp\vue2-webpack5\hello-world\node_modules\tapable\lib\Hook.js:18:14)
at C:\tmp\vue2-webpack5\hello-world\node_modules\webpack\lib\Compiler.js:468:23
Error: mochapack exited with code 1.
at ChildProcess.<anonymous> (C:\tmp\vue2-webpack5\hello-world\node_modules\@vue\cli-plugin-unit-mocha\index.js:84:18)
at ChildProcess.emit (events.js:327:22)
at ChildProcess.cp.emit (C:\tmp\vue2-webpack5\hello-world\node_modules\cross-spawn\lib\enoent.js:34:29)
at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test:unit: `vue-cli-service test:unit`
npm ERR! Exit status 1
This is most likely due to the fact that mochapack is not compatible with webpack 5: sysgears/mochapack#82
Background of this issue is that I am using the Typescript nullish-coalescing-operator
??
(e.g. const a = b ?? c) in my real codebase.
For building (npm run build) or serving (npm run serve), this works as babel transpiles it correctly.
But when trying to test the function using a unit test, it failed to execute as I was still using webpack 4 (using @vue/cli-plugin-webpack-4). The original error from this point was
Module parse failed: Unexpected token (119:37)
File was processed with these loaders:
* ./node_modules/cache-loader/dist/cjs.js
* ./node_modules/babel-loader/lib/index.js
* ./node_modules/ts-loader/index.js
You may need an additional loader to handle the result of these loaders.
| */
| [_constants.ABC.MY_GETTER]: () => param => {
> return param.name ?? "abc";
| },
|
When searching through issues, I stepped over a note that webpack ^5 is required to get such nullish-coalescing-operator's to work also in unittests (without babel) - that's why I tried to upgrade my project to webpack5 but then I ran into the issue that the shipped version of mochapack does not support webpack5.
So it seems there is currently no way of using vue/cli5 with webpack5 and keep building and unit-testing working?
The text was updated successfully, but these errors were encountered:
Version
5.0.0-alpha.8
Reproduction link
https://github.com/sceee/vue2-webpack5-unittest-nullish-coalescing-operator-error-demo
Environment info
Steps to reproduce
Check out repository
npm run build
-> worksnpm run test:unit
-> failsWhat is expected?
Unit tests can be executed after setting up a project with vue/cli 5.
What is actually happening?
The following error occurs:
This is most likely due to the fact that mochapack is not compatible with webpack 5: sysgears/mochapack#82
Background of this issue is that I am using the Typescript nullish-coalescing-operator
(e.g.
const a = b ?? c
) in my real codebase.For building (
npm run build
) or serving (npm run serve
), this works as babel transpiles it correctly.But when trying to test the function using a unit test, it failed to execute as I was still using webpack 4 (using
@vue/cli-plugin-webpack-4
). The original error from this point wasWhen searching through issues, I stepped over a note that
webpack ^5
is required to get such nullish-coalescing-operator's to work also in unittests (without babel) - that's why I tried to upgrade my project to webpack5 but then I ran into the issue that the shipped version of mochapack does not support webpack5.So it seems there is currently no way of using vue/cli5 with webpack5 and keep building and unit-testing working?
The text was updated successfully, but these errors were encountered: