The following error message appears when npm run build of vue project: import/no-unresolved

error Unable to resolve path to module '@/utils/china.json' import/no-unresolved

Error screenshotInsert image description here

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.
Insert image description here

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.

Insert image description hereCompile 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.
Insert image description here

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
Insert image description here
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.
Insert image description here

Repair^5.0.25.0.2Insert image description here

# 删除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
Insert image description here
Report thisimport/no-unresolvedError:

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
Insert image description here
Execute the command

# 重新装依赖
npm i 
# 重新编译
npm run build

Build successful
Insert image description here

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.

Guess you like

Origin blog.csdn.net/m0_37680500/article/details/132333045