首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Vue.config.js无法识别要求(Webpack)

Vue.config.js无法识别要求(Webpack)
EN

Stack Overflow用户
提问于 2021-12-09 09:56:36
回答 1查看 124关注 0票数 0

我通过CLI创建了一个vue3.0 + ts项目,当我添加vue.config.js时,它在require上总是有错误

代码语言:javascript
复制
const webpack = require('webpack');
const path = require('path');

错误是

代码语言:javascript
复制
module "d:/learning/vue-3-ts-demo/node_modules/webpack/types"

Require statement not part of import statement`.

我安装了webpack 5.65.0

我的packages.json:

代码语言:javascript
复制
{
  "name": "vue-3-ts-demo",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "core-js": "^3.6.5",
    "vue": "^3.0.0",
    "vue-router": "^4.0.0-0",
    "vuex": "^4.0.0-0"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^4.18.0",
    "@typescript-eslint/parser": "^4.18.0",
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-plugin-typescript": "~4.5.0",
    "@vue/cli-plugin-vuex": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/compiler-sfc": "^3.0.0",
    "@vue/eslint-config-typescript": "^7.0.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^7.0.0",
    "sass": "^1.26.5",
    "sass-loader": "^8.0.2",
    "typescript": "~4.1.5",
    "webpack": "^5.65.0"
  }
}

这是一个新的vue项目,问题是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-10 02:11:59

错误是模块"d:/learning/vue-3-ts-demo/node_modules/webpack/types“

Require语句,而不是导入语句的一部分。

对于此错误,我通过在'@typescript-eslint/no-var-requires': 0中添加.eslintrc.js来对其进行查询。

代码语言:javascript
复制
rules: {
'@typescript-eslint/no-var-requires': 0
}

我安装了webpack 5.65.0

由于我的vue CLI是4.5.14,我也重新安装了webpack版本,作为4.x,它终于工作了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70287877

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档