如题
webpack.base.conf.js 配置如下:
src下有Home.vue跟store目录,store下面有个index.js
页面引入:
import store from 'store'
控制台报错:
ERROR in ./src/Home.vue
✘ https://google.com/#q=import%2Fno-unresolved Unable to resolve path to module 'store'
/Users/xx/Documents/demo/src/Home.vue:35:19
import store from 'store'
^
✘ 1 problem (1 error, 0 warnings)
Errors:
1 https://google.com/#q=import%2Fno-unresolved
ERROR in ./~/babel-loader?presets[]=es2015&plugins[]=transform-runtime&comments=false!./~/vue-loader/lib/selector.js?type=script&index=0!./src/Home.vue
Module not found: Error: Cannot resolve module 'store' in /Users/xx/Documents/demo/src
@ ./~/babel-loader?presets[]=es2015&plugins[]=transform-runtime&comments=false!./~/vue-loader/lib/selector.js?type=script&index=0!./src/Home.vue 15:13-29
但是我页面引入时改成相对路径又可以:
import store from './store'
……
重新vue init了一个写了alias确实没问题… 看样子问题出在eslint上,贴一下eslintrc,有空的大神帮我看看
module.exports = {
root: true,
// parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
},
extends: 'airbnb-base',
// required to lint *.vue files
plugins: [
'html'
],
// add your custom rules here
'rules': {
'no-debugger': process.env.NODE_ENV === 'production' ? 1 : 0,
"semi": [2, "never"],
"no-console": [0],
"space-before-function-paren": [2, "always"],
"prefer-const": [0],
"eol-last": [0],
"no-param-reassign": [0],
"no-shadow": [0],
"arrow-body-style": [0],
"comma-dangle": [0],
"space-in-parens": [0],
"prefer-rest-params": [0],
"quote-props": [0],
"func-names": [0],
"guard-for-in": [0],
"object-shorthand": [0],
"no-use-before-define": [0],
"computed-property-spacing": [0],
"consistent-return": [0],
"camelcase": [0],
"no-return-assign": [0],
"no-extend-native": [0],
"no-else-return": [0],
"dot-notation": [0],
"prefer-template": [0],
"no-restricted-syntax": [0],
"no-unresolved": [0]
}
}
大兄弟,我刚刚也是这个问题。
用你采纳的方法也不行,后来琢磨了一下,解决了。
问题出在你是不是
npm run dev
后改的webpack.base.conf.js
这个文件?这个东西是在
npm run dev
后就运行一遍的。如果改动的话,必须重新npm run dev
。答案不应该是 eslint 的问题。