error Unable to resolve path to module '@/utils/china.json' import/no-unresolved
Error screenshot
At first glance, the problem is that the .png image resource does not exist
But it is certain, certain, and absolutely that the image does exist. If you don’t believe me, just look at the picture.
But to be honest, it was fine yesterday but today I can’t pretend to be dependent.
Solution 1 (not recommended):
Add a line of configuration in the.eslintrc.js
file, as shown below:'import/no-unresolved': 'off'
Ignore this type of error,but you must ensure that the files really exist.
Compile again and no error will be reported:
npm run build
Because it really doesn’t verify it for you. I filled it in randomly and it didn’t report an error, soit is not recommended.
There is also this way of writing on the Internet, and the same principle is true.
"import/no-unresolved": [
2,
{
"ignore": ["^@/"] // @ 是设置的路径别名
},
],
Solution 2 (recommended):
On the left is the newly pulled dependency package_lock.json. On the right is the package_lock.json that did not report an error last time
I guess it may be a problem with this version. Search all the way up to see if it is Who has used eslint-import-resolver-node ^0.3.4
? Global search for package_lock.json found that it is @vue/eslint-config-airbnb 5.3.0
.
Repair^5.0.2
为5.0.2
# 删除node_modules 和 package_lock.json
rm -rf node_modules
rm -rf package_lock.json
# 重新安装依赖
npm i
# 尝试重新编译
npm run build
It may compile normally.
~~If it still doesn’t work and an error is reported, then continue reading
Report thisimport/no-unresolved
Error:
After careful observation this time, I found in package_lock.json: The version of eslint-import-resolver-node
introduced by @vue/eslint-config-airbnb is still 0.3.9. According to the last time, no error will be reported. It is version 0.3.7.
Then the key solution comes: add one directly"eslint-import-resolver-node": "0.3.7"
Fix this version
Execute the command
# 重新装依赖
npm i
# 重新编译
npm run build
Build successful
The final installed version is eslint-import-resolver-node: 0.3.7.
Because the ^ symbol will install the latest version.
The most important thing is to modify package.json to solve the problem.