当前位置:   article > 正文

Error: Cannot find module ‘vue-template-compiler‘ 问题解决_error: cannot find module 'vue-template-compiler

error: cannot find module 'vue-template-compiler

启动Vuepress项目时报了如下错误:Error: Cannot find module 'vue-template-compiler'

Error: Cannot find module 'vue-template-compiler'
Require stack:
- /usr/local/lib/node_modules/vuepress/node_modules/vue-loader/lib/compiler.js
- /usr/local/lib/node_modules/vuepress/node_modules/vue-loader/lib/resolveScript.js
- /usr/local/lib/node_modules/vuepress/node_modules/vue-loader/lib/select.js
- /usr/local/lib/node_modules/vuepress/node_modules/vue-loader/lib/index.js
- /usr/local/lib/node_modules/vuepress/node_modules/@vuepress/core/lib/node/webpack/createBaseConfig.js
- /usr/local/lib/node_modules/vuepress/node_modules/@vuepress/core/lib/node/webpack/createClientConfig.js
- /usr/local/lib/node_modules/vuepress/node_modules/@vuepress/core/lib/node/dev/index.js
- /usr/local/lib/node_modules/vuepress/node_modules/@vuepress/core/lib/node/App.js
- /usr/local/lib/node_modules/vuepress/node_modules/@vuepress/core/lib/index.js
- /usr/local/lib/node_modules/vuepress/lib/registerCoreCommands.js
- /usr/local/lib/node_modules/vuepress/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:931:15)
    at Function.resolve (internal/modules/cjs/helpers.js:113:19)
    at loadFromContext (/usr/local/lib/node_modules/vuepress/node_modules/vue-loader/lib/compiler.js:30:26)
    at loadTemplateCompiler (/usr/local/lib/node_modules/vuepress/node_modules/vue-loader/lib/compiler.js:37:12)
    at exports.resolveCompiler (/usr/local/lib/node_modules/vuepress/node_modules/vue-loader/lib/compiler.js:25:23)
    at VueLoaderPlugin.apply (/usr/local/lib/node_modules/vuepress/node_modules/vue-loader/lib/plugin-webpack4.js:91:22)
    at VueLoaderPlugin.apply (/usr/local/lib/node_modules/vuepress/node_modules/vue-loader/lib/plugin.js:13:16)
    at webpack (/usr/local/lib/node_modules/vuepress/node_modules/webpack/lib/webpack.js:51:13)
    at DevProcess.createServer (/usr/local/lib/node_modules/vuepress/node_modules/@vuepress/core/lib/node/dev/index.js:241:22)
    at error (/usr/local/lib/node_modules/vuepress/node_modules/@vuepress/core/lib/node/App.js:477:14)
    at new Promise (<anonymous>)
    at App.dev (/usr/local/lib/node_modules/vuepress/node_modules/@vuepress/core/lib/node/App.js:470:25)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

解决方案一: 在项目根目录下安装vue-template-compiler模块:npm install vue-template-compiler --save-dev

[root@iZbp1ge4ctw809v4lhhrnaZ ~]# npm install vue-template-compiler --save-dev
npm WARN saveError ENOENT: no such file or directory, open '/root/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/root/package.json'
npm WARN root No description
npm WARN root No repository field.
npm WARN root No README data
npm WARN root No license field.

+ vue-template-compiler@2.7.16
added 3 packages from 2 contributors in 0.525s


   ╭────────────────────────────────────────────────────────────────╮
   │                                                                │
   │      New major version of npm available! 6.14.1810.2.5      │
   │   Changelog: https://github.com/npm/cli/releases/tag/v10.2.5   │
   │               Run npm install -g npm to update!                │
   │                                                                │
   ╰────────────────────────────────────────────────────────────────╯
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

解决方案二: 清除缓存并重新安装依赖

npm cache clean --force
  • 1

然后,删除项目根目录下的node_modules文件夹,重新安装项目的依赖:

npm install
  • 1

解决方案三: Vue版本不匹配导致,可以查看package.json版本管理中的vue-template-compiler版本

"dependencies": {
  "vue-template-compiler": "^2.7.7",
}
  • 1
  • 2
  • 3

然后通过 npm list vue 查看已安装的Vue版本。

PS E:\myblog\blog> npm list vue    
myblog@1.0.0 E:\myblog\blog
`-- @vssue/vuepress-plugin-vssue@1.4.8
  `-- vssue@1.4.8
    `-- vue@2.7.8 
  • 1
  • 2
  • 3
  • 4
  • 5

确保项目中安装的Vue版本和"vue-template-compiler": "^2.7.7"兼容。如果不兼容,尝试升级或降级Vue版本,或更新vue-template-compiler模块的版本。

解决方案四: 如果你的项目使用了webpack作为构建工具,那么可能是webpack配置的问题导致的错误,检查webpack配置,通常是webpack.config.jsvue.config.js,确保vue-loader的版本与vue-template-compiler模块的版本兼容。如果以上方法都没有解决问题,那么可能是其它依赖模块的问题导致的错误,检查项目中的其他依赖模块是否与vue-template-compiler模块的版本兼容

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/515861
推荐阅读
相关标签
  

闽ICP备14008679号