vue webpack 模板缺少解析器
vue webpack template missing parser
我刚刚使用 webpack 模板设置了一个 vue 项目,如下所述:http://vuejs-templates.github.io/webpack/
然而,在 运行ning npm 运行 dev 之后,为了测试模板是否正常工作,我得到了这个错误:
Failed to compile with 2 errors 21:49:02
error in ./src/App.vue
Module build failed: Error: No parser and no file path given, couldn't infer a parser.
at normalize (path\node_modules\prettier\index.js:7051:13)
at formatWithCursor (path\node_modules\prettier\index.js:10370:12)
at path\node_modules\prettier\index.js:31115:15
at Object.format (path\node_modules\prettier\index.js:31134:12)
at Object.module.exports (path\node_modules\vue-loader\lib\template-compiler\index.js:80:23)
@ ./src/App.vue 11:0-354
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
error in ./src/components/HelloWorld.vue
Module build failed: Error: No parser and no file path given, couldn't infer a parser.
at normalize (path\node_modules\prettier\index.js:7051:13)
at formatWithCursor (path\node_modules\prettier\index.js:10370:12)
at path\node_modules\prettier\index.js:31115:15
at Object.format (path\node_modules\prettier\index.js:31134:12)
at Object.module.exports (path\node_modules\vue-loader\lib\template-compiler\index.js:80:23)
我做错了什么?
Prettier 在他们今天发生的 1.13.0
更新中导致了这种倒退。降级到以前的版本以修复此错误:
npm install --save-dev prettier@1.12.0
npm run dev
这应该可以解决问题。
由于vue-cli
在这里使用了更漂亮的API接口并对选项进行了硬编码,并且在项目@vue/component-compiler-utils
.
中添加了更漂亮的依赖项
您可以尝试 npm i prettier@~1.12.0
在此处强制使用更漂亮的版本。
顺便说一句,有人 pull request 修复了
我在使用 yarn 时遇到了同样的错误,但尝试了 npm i
和 npm run dev
并且成功了。
yarn v v1.5.1
npm -v 5.6.0
node -v v10.0.0
如果您使用的是 Yarn,请将此添加到您的 package.json
以强制 @vue/component-compiler-utils
使用正确的版本:
"resolutions": {
"@vue/component-compiler-utils/prettier": "1.12.1"
}
然后进行全新安装。
我在 Docker 上使用 Nuxt/Vue。我在 docker 构建时遇到了同样的错误。
执行以下命令后无效
rm -rf node_modules
npm install --save-dev prettier@1.12.0
npm run dev
所以我像这样编辑了 Docker 文件并且成功了。
FROM node:8.11
RUN mkdir -p /app
COPY . /app
WORKDIR /app
RUN npm install && npm cache verify
RUN npm install --save-dev prettier@1.12.0
RUN npm run build
EXPOSE 3000
CMD ["npm", "run", "express"]
如果您使用的是 laravel-mix
那么这对我来说已经解决了:
删除 .\node_modules,删除 .\yarn.lock 然后将以下内容添加到 .\package.json
"dependencies": {
...
"prettier": "1.12.1",
"vue-loader": "13.7.0"
...
},
"resolutions": {
"laravel-mix/vue-loader": "13.7.0",
"vue-loader/prettier": "1.12.1"
}
运行 纱线,一切都应该正常工作。
在vue-loader@13.7.2和vue-loader@14.2.3中修复。所以就升级吧。
我刚刚使用 webpack 模板设置了一个 vue 项目,如下所述:http://vuejs-templates.github.io/webpack/
然而,在 运行ning npm 运行 dev 之后,为了测试模板是否正常工作,我得到了这个错误:
Failed to compile with 2 errors 21:49:02
error in ./src/App.vue
Module build failed: Error: No parser and no file path given, couldn't infer a parser.
at normalize (path\node_modules\prettier\index.js:7051:13)
at formatWithCursor (path\node_modules\prettier\index.js:10370:12)
at path\node_modules\prettier\index.js:31115:15
at Object.format (path\node_modules\prettier\index.js:31134:12)
at Object.module.exports (path\node_modules\vue-loader\lib\template-compiler\index.js:80:23)
@ ./src/App.vue 11:0-354
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
error in ./src/components/HelloWorld.vue
Module build failed: Error: No parser and no file path given, couldn't infer a parser.
at normalize (path\node_modules\prettier\index.js:7051:13)
at formatWithCursor (path\node_modules\prettier\index.js:10370:12)
at path\node_modules\prettier\index.js:31115:15
at Object.format (path\node_modules\prettier\index.js:31134:12)
at Object.module.exports (path\node_modules\vue-loader\lib\template-compiler\index.js:80:23)
我做错了什么?
Prettier 在他们今天发生的 1.13.0
更新中导致了这种倒退。降级到以前的版本以修复此错误:
npm install --save-dev prettier@1.12.0
npm run dev
这应该可以解决问题。
由于vue-cli
在这里使用了更漂亮的API接口并对选项进行了硬编码,并且在项目@vue/component-compiler-utils
.
您可以尝试 npm i prettier@~1.12.0
在此处强制使用更漂亮的版本。
顺便说一句,有人 pull request 修复了
我在使用 yarn 时遇到了同样的错误,但尝试了 npm i
和 npm run dev
并且成功了。
yarn v v1.5.1
npm -v 5.6.0
node -v v10.0.0
如果您使用的是 Yarn,请将此添加到您的 package.json
以强制 @vue/component-compiler-utils
使用正确的版本:
"resolutions": {
"@vue/component-compiler-utils/prettier": "1.12.1"
}
然后进行全新安装。
我在 Docker 上使用 Nuxt/Vue。我在 docker 构建时遇到了同样的错误。
执行以下命令后无效
rm -rf node_modules
npm install --save-dev prettier@1.12.0
npm run dev
所以我像这样编辑了 Docker 文件并且成功了。
FROM node:8.11
RUN mkdir -p /app
COPY . /app
WORKDIR /app
RUN npm install && npm cache verify
RUN npm install --save-dev prettier@1.12.0
RUN npm run build
EXPOSE 3000
CMD ["npm", "run", "express"]
如果您使用的是 laravel-mix
那么这对我来说已经解决了:
删除 .\node_modules,删除 .\yarn.lock 然后将以下内容添加到 .\package.json
"dependencies": {
...
"prettier": "1.12.1",
"vue-loader": "13.7.0"
...
},
"resolutions": {
"laravel-mix/vue-loader": "13.7.0",
"vue-loader/prettier": "1.12.1"
}
运行 纱线,一切都应该正常工作。
在vue-loader@13.7.2和vue-loader@14.2.3中修复。所以就升级吧。