Can‘t resolve ‘path‘ in ‘/Users/72cy-0101-01-0017/Desktop/vue3-elementplus-admin/src/utils‘

问题描述:
使用vuecli@5 创建的项目使用
import path from ‘path’ 报错如下


Module not found: Error: Can't resolve 'path' in '/Users/72cy-0101-01-0017/Desktop/vue3-elementplus-admin/src/utils'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
	- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "path": false }

webpack < 5默认用于包含node.js核心模块的polyfills。现在情况已经不一样了。验证你是否需要这个模块,并为它配置一个polyfill。)
解决方案:

npm install -D path-browserify

原因是我用的vue-cli5.0创建的项目,已经没有了原有的webpack配置,只有vue.config.js

最后把配置放在了configureWebpack即可解决

  configureWebpack: {
    resolve: {
      fallback: { path: require.resolve('path-browserify') }
    }
  }

你可能感兴趣的:(一些问题,javascript,前端,vue.js)