vue-template-compiler / package.json每个新项目都缺少模块

时间:2018-12-10 20:09:01

标签: node.js vue.js npm vuejs2

当前,我从Linux切换到Windows,并开始创建编程环境。我不记得linux上的类似问题,但要点是: 1。。已安装Node.js 2。 npm install -g @vue/cli用于CLI安装 3。 vue create my-app 4。 npm run serve 给了

    ERROR Error: Cannot find module 'vue-template-compiler/package.json'
Error: Cannot find module 'vue-template-compiler/package.json'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at api.chainWebpack.webpackConfig (D:\vueTest\test\node_modules\@vue\cli-service\lib\config\base.js:73:32)
at webpackChainFns.forEach.fn (D:\vueTest\test\node_modules\@vue\cli-service\lib\Service.js:225:40)
at Array.forEach (<anonymous>)
at Service.resolveChainableWebpackConfig (D:\vueTest\test\node_modules\@vue\cli-service\lib\Service.js:225:26)
at Service.resolveWebpackConfig (D:\vueTest\test\node_modules\@vue\cli-service\lib\Service.js:229:48)
at PluginAPI.resolveWebpackConfig (D:\vueTest\test\node_modules\@vue\cli-service\lib\PluginAPI.js:115:25)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test@0.1.0 serve: vue-cli-service serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test@0.1.0 serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Michal\AppData\Roaming\npm-cache_logs\2018-12-09T203013_264Z-debug.log`

5。 vue-cli-service inspect --mode production

ERROR Error: Cannot find module 'vue-template-compiler/package.json'

Error: Cannot find module 'vue-template-compiler/package.json'
at Function.Module.resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module.load (internal/modules/cjs/loader.js:506:25)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at api.chainWebpack.webpackConfig (D:\vueTest\test\nodemodules\@vue\cli-service\lib\config\base.js:73:32)
at webpackChainFns.forEach.fn (D:\vueTest\test\nodemodules\@vue\cli-service\lib\Service.js:225:40)
at Array.forEach (<anonymous>)
at Service.resolveChainableWebpackConfig (D:\vueTest\test\nodemodules\@vue\cli-service\lib\Service.js:225:26)
at Service.resolveWebpackConfig (D:\vueTest\test\nodemodules\@vue\cli-service\lib\Service.js:229:48)
at PluginAPI.resolveWebpackConfig (D:\vueTest\test\node_modules\@vue\cli-service\lib\PluginAPI.js:115:25)`

6。。我尝试了vue ui,但故事相同,因此我为创建的应用npm install vue-template-compiler安装了缺少的模块,运行顺利,添加了软件包。 7。 vue run serve,开始构建,然后:

 ERROR  Failed to compile with 3 errors                  
This dependency was not found:

* vue in ./src/main.js, ./src/App.vue and 1 other

To install it, you can run: npm install --save vue

8。。因此,我运行npm install --save vue,然后终于npm run serve工作了:

 DONE  Compiled successfully in 2536ms  

我使用vue crate my-app-name创建的每个项目都必须手动安装vue-template-compiler,但是随后我尝试使用create vue init webpack-simple my-next-app进行构建,所有内容都没有问题并可以运行。 使用create - create a new project powered by vue-cli-serviceinit - generate a project from a remote template (legacy API, requires @vue/cli-init)

创建新的vue项目有什么区别?

Ps。是的,我尝试在全球安装vue-template-compile r。

Environment Info:

  System:
    OS: Windows 10
    CPU: (8) x64 Intel(R) Core(TM) i7-4710HQ CPU @ 2.50GHz
  Binaries:
    Node: Not Found
    Yarn: Not Found
    npm: 5.0.4 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: 42.17134.1.0
  npmPackages:
    @vue/babel-preset-app:  3.2.0
    @vue/cli-overlay:  3.2.0
    @vue/cli-plugin-babel: ^3.2.0 => 3.2.0
    @vue/cli-plugin-eslint: ^3.2.0 => 3.2.1
    @vue/cli-service: ^3.2.0 => 3.2.0
    @vue/cli-shared-utils:  3.2.0
    @vue/component-compiler-utils:  2.3.0
    @vue/preload-webpack-plugin:  1.1.0
    @vue/web-component-wrapper:  1.2.0
    babel-helper-vue-jsx-merge-props:  2.0.3
    babel-plugin-transform-vue-jsx:  4.0.1
    eslint-plugin-vue: ^5.0.0-0 => 4.7.1
    vue-eslint-parser:  2.0.3
    vue-hot-reload-api:  2.3.1
    vue-loader:  15.4.2
    vue-style-loader:  4.1.2
    vue-template-es2015-compiler:  1.6.0
  npmGlobalPackages:
    @vue/cli: Not Found

为什么vue在新项目中看不到@ vue / cli?那是我安装的第一件事:/

3 个答案:

答案 0 :(得分:1)

最近我遇到了同样的问题,我确实使用更新包修复了当前版本的一些软件包,如下所示。

  1. “ vue”:“ 2.5.17”
  2. “ vue-template-compiler”:“ 2.5.17”

答案 1 :(得分:0)

最近我遇到了同样的问题,我使用下面的最新版本的一些软件包进行了更新以解决问题。

“ vue”:“ 2.5.22” “ vue-template-compiler”:“ 2.5.22

我也在Vue.js论坛中发布了 https://forum.vuejs.org/t/installation-nightmare/54705

新用户很难弄清楚如何以及在何处进行修复

帮助我的是https://itnext.io/vuejs-and-webpack-4-from-scratch-part-1-94c9c28a534ahttps://itnext.io/getting-started-vue-js-and-visual-studio-code-6990f92e918a

答案 2 :(得分:0)

here所述,您需要手动安装vue-template-compiler,运行npm i -g vue-template-compiler可以解决问题。