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

Module not found: '@vue/server-renderer' error with Vue test utils (Mocha Chai) #1734

Closed
andyghiuta opened this issue Sep 29, 2020 · 16 comments · Fixed by vuejs/vue-cli#6097
Closed

Comments

@andyghiuta
Copy link

Version

16.0.0-beta.8

Reproduction link

https://github.com/andyghiuta/vue-loader-server-renderer-issue

Steps to reproduce

npm run test:unit

What is expected?

Tests to complete (fail or pass)

What is actually happening?

Tests fail:

vue-cli-service test:unit

 WEBPACK  Compiling...

  [=========================] 98% (after emitting)

 ERROR  Failed to compile with 1 errors

This dependency was not found:

* @vue/server-renderer in ./node_modules/cache-loader/dist/cjs.js??ref--13-0!./node_modules/babel-loader/lib!./node_modules/vue-loader-v16/dist/templateLoader.js??ref--6!./node_modules/cache-loader/dist/cjs.js??ref--1-0!./node_modules/vue-loader-v16/dist??ref--1-1!./src/components/HelloWorld.vue?vue&type=template&id=469af010&scoped=true&bindings={"msg":"props"}

To install it, you can run: npm install --save @vue/server-renderer
  [=========================] 100% (completed)

 WEBPACK  Failed to compile with 1 error(s)

Error in ./src/components/HelloWorld.vue?vue&type=template&id=469af010&scoped=true&bindings={"msg":"props"}

  Module not found: '@vue/server-renderer' in 'D:\work\www\node\hello-vue3-cli\src\components'

 ERROR  mochapack exited with code 1.

This is a brand new scaffolded app, no extras.

(*) Choose Vue version
 (*) Babel
 ( ) TypeScript
 ( ) Progressive Web App (PWA) Support
 ( ) Router
 ( ) Vuex
 ( ) CSS Pre-processors
 (*) Linter / Formatter
>(*) Unit Testing
 ( ) E2E Testing
Please pick a preset: Manually select features
? Check the features needed for your project: Choose Vue version, Babel, Linter, Unit
? Choose a version of Vue.js that you want to start the project with 3.x (Preview)
? Pick a linter / formatter config: Airbnb
? Pick additional lint features: Lint on save
? Pick a unit testing solution: Mocha
? Where do you prefer placing config for Babel, ESLint, etc.? In dedicated config files
? Save this as a preset for future projects? (y/N)

Deps:

"dependencies": {
    "core-js": "^3.6.5",
    "vue": "^3.0.0-0"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-unit-mocha": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/compiler-sfc": "^3.0.0-0",
    "@vue/eslint-config-airbnb": "^5.0.2",
    "@vue/test-utils": "^2.0.0-0",
    "babel-eslint": "^10.1.0",
    "chai": "^4.1.2",
    "eslint": "^6.7.2",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-vue": "^7.0.0-0",
    "less": "^3.0.4",
    "less-loader": "^5.0.0"
  }
@janriemer
Copy link

janriemer commented Oct 3, 2020

Same problem for me. I use TypeScript instead of babel, though.

This dependency was not found:

* @vue/server-renderer in ./node_modules/vue-loader-v16/dist/templateLoader.js??ref--5!./node_modules/cache-loader/dist/cjs.js??ref--1-0!./node_modules/vue-loader-v16/dist??ref--1-1!./src/app/HelloWorld.vue?vue&type=template&id=812b7072&scoped=true&bindings={}

@Korijn
Copy link

Korijn commented Oct 3, 2020

Temporary workaround is to pin vue-loader-v16 to beta 7 in your package.json, like so:

"vue-loader-v16": "npm:vue-loader@16.0.0-beta.7"

I use practically the same setup with cucumber-js instead of mocha (using a custom vue-cli plugin) and encountered exactly the same issue.

@janriemer
Copy link

@Korijn Woohooo, that did the trick! 🎉
Thank you so much for the quick response! ❤️

@damianof
Copy link

damianof commented Oct 6, 2020

I started experiencing this issue to yesterday, but the fix suggested by @Korijn does not seem to make a difference for me. (I am also using TypeScript)

Corrected: The fix actually worked after deleting package-lock.json and node_modules and doing npm install again. Thank you @Korijn

damianof pushed a commit to damianof/large-scale-apps-my-vue3-project that referenced this issue Oct 6, 2020
damianof pushed a commit to damianof/large-scale-apps-my-vue3-project that referenced this issue Oct 6, 2020
@Korijn
Copy link

Korijn commented Oct 6, 2020

I started experiencing this issue to yesterday, but the fix suggested by @Korijn does not seem to make a difference for me. (I am also using TypeScript)

You applied the workaround correctly (judging from your package-lock.json). It must be related to your use of typescript then I guess.

Sorry, I can't help you with that.

@damianof
Copy link

damianof commented Oct 6, 2020

I started experiencing this issue to yesterday, but the fix suggested by @Korijn does not seem to make a difference for me. (I am also using TypeScript)

You applied the workaround correctly (judging from your package-lock.json). It must be related to your use of typescript then I guess.

Sorry, I can't help you with that.

I updated my comment above. Thank you again.

damianof pushed a commit to damianof/large-scale-apps-my-vue3-project that referenced this issue Oct 10, 2020
FSMaxB added a commit to communityvi/communityvi that referenced this issue Nov 11, 2020
@creynir
Copy link

creynir commented Nov 22, 2020

Any workaround on this one? I'm getting this issue on new project created with latest vue-cli. I see vue-loader v15.9.5 and vue-loader-v16 v16.0.0-rc.2 in my node_modules for some reason

sodatea added a commit to sodatea/vue-loader that referenced this issue Nov 27, 2020
This option provides a solution for vuejs#1734

When testing with mocha + mochapack, even though the target
environment is `node`, the compiled component is expected to be run
with `jsdom` rather than with a Node.js server, so it should still be
a client bundle.
sodatea added a commit that referenced this issue Nov 30, 2020
…1764)

This option provides a solution for #1734

When testing with mocha + mochapack, even though the target
environment is `node`, the compiled component is expected to be run
with `jsdom` rather than with a Node.js server, so it should still be
a client bundle.
@sodatea
Copy link
Member

sodatea commented Nov 30, 2020

See vuejs/vue-cli#6097
Use vue-loader 16.1.0+ and explicitly disable the isServerBuild option.

Note: the given reproduction project still fails because of another long-standing issue with project names starting with vue-loader 😂 99a5196

@HelloMyDevWorld
Copy link

but where to set isServerBuild ?!?!

@HelloMyDevWorld
Copy link

always give examples to people DUDE

@sodatea
Copy link
Member

sodatea commented Dec 3, 2020

The first link IS THE EXAMPLE, DUDE.

@Sergej-Popov
Copy link

Here is a more down to earth example for the rest of us who use less sophisticated webpack config.
Goes to vue.config.js as per https://cli.vuejs.org/guide/webpack.html

module.exports = {
  chainWebpack: config => {
    config.module
      .rule('vue')
      .use('vue-loader')
      .loader('vue-loader')
      .tap(options => {
        options.isServerBuild = false
        return options
      })
  }
}

@sodatea
Copy link
Member

sodatea commented Dec 8, 2020

@Sergej-Popov The .loader line is extraneous and may cause errors under some circumstances.

@Sergej-Popov
Copy link

Sergej-Popov commented Dec 8, 2020

@sodatea Not saying you are wrong, but that's how documentation suggests doing it.
https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader

@sodatea
Copy link
Member

sodatea commented Dec 8, 2020

Oops. No wonder it's used in so many places! I think we need to update the documentation.

@ghost
Copy link

ghost commented Dec 28, 2020

Just to clarify for anyone coming across this as this is a confusing thread and the info scattered elsewhere on SO and in other vue projects wasn't clear.

For a Vue 3 CLI app configured to use typescript and mocha / chai all I had to do was add a vue.config.js file (there wasn't one by default) to the root of my project and have the following in that file:

  chainWebpack: config => {
    config.module
      .rule('vue')
      .use('vue-loader')
      .tap(options => {
        options.isServerBuild = false;
        return options;
      });
  }
};

For good measure I removed my package-lock.json and my node_modules directories and ran npm install again. I'm not 100% sure that step was required as I was doing a bunch of variants but it doesn't hurt and likely could clear up other dependency problems..
Now I can safely run npm run test:unit and don't get any errors. Note I didn't update my package.json to pin the vue-template-compiler as it wasn't necessary if you add the vue.config.js file.

ZanderOlidan pushed a commit to ZanderOlidan/vue-cli-service-chalkfix that referenced this issue Feb 5, 2024
ZanderOlidan pushed a commit to ZanderOlidan/vue-cli-service-chalkfix that referenced this issue Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants