1

I am trying to add a watcher in my "test" script I defined in the package.json.

What I want to achieve is quite simple : I want the command line "npm run test" to be executed each time I modify a file that ends with .spec.js in the tests/FrontEnd directory.

What I get when I run "npm run test" are the following lines :

enter image description here

This is how I've modified the script to get the watcher :

    "test": "mocha-webpack --webpack-config=node_modules/laravel-mix/setup/webpack.config.js --require tests/Frontend/setup.js tests/Frontend/**/*.spec.js --watch"

Everything works when I remove the --watch at the end of my script.

My dependencies versions are here :

"devDependencies": {
        "@nuxtjs/vuetify": "^1.10.1",
        "@vue/test-utils": "^1.0.0-beta.32",
        "axios": "^0.19",
        "bootstrap": "^4.4.1",
        "cross-env": "^5.2.1",
        "css-loader": "^3.4.2",
        "deepmerge": "^4.2.2",
        "expect": "^25.1.0",
        "fibers": "^4.0.2",
        "jquery": "^3.4.1",
        "jsdom": "^16.2.1",
        "jsdom-global": "^3.0.2",
        "json-loader": "^0.5.7",
        "laravel-mix": "^4.0.7",
        "lodash": "^4.17.13",
        "mocha": "^4.0.1",
        "mocha-webpack": "^0.7.0",
        "popper.js": "^1.12",
        "preload-webpack-plugin": "^3.0.0-beta.4",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.26.2",
        "sass-loader": "^7.3.1",
        "style-loader": "^1.1.3",
        "vue": "^2.6.11",
        "vue-template-compiler": "^2.6.11",
        "vue-test-utils": "^1.0.0-beta.11",
        "webpack": "^4.42.0"
    },

Thanks for the help !

1 Answer 1

1

This looks like an incompatibility of the mocha-webpack plugin version you're using and the webpack plugin you're using. The 0.7.0 version of mocha-webpack is written for an older webpack plugin system, and as such might not work with the newer one. In the webpack version you're using 4.20.0 (approx), the chunk property does not have the property/accessor of modules, and that's where you see the error.

And this code path is run only in watch mode (from what I was able to gather from that version's codebase), so this didn't happen when you didn't provide --watch.

Try upgrading the mocha-webpack plugin to the latest stable version.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, unfortunately going back to webpack 3 didn't solve the issue.. Now I have another problem. "Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration has an unknown property 'optimization'." I've tried to add UfligyJsPlugin to solve this without success.. Thanks for your help !
webpack config between v3 and v4 is different, so the error you see is because of that. Did you try upgrading mocha-webpack though?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.