【报错】:Module path has been externalized for browser...

简介: 【报错】:Module path has been externalized for browser...

@[toc]

Vite2+Vue3下引入path模块报错:Module "path" has been externalized for brower compatibility and cannot be accesed in client code

报错

在这里插入图片描述
原因是 vite 源码中设定了不允许在客户端代码中访问内置模块代码。

解决方法

1,安装npm install path-browserify

2,使用 path-browserify 代替 path 模块

3,不再使用import path from 'path',改为import path from 'path-browserify'

相关文章
|
7月前
webpack 使用打包报错 ERROR in node_modules\@types\node\ts4.8\assert.d.ts
webpack 使用打包报错 ERROR in node_modules\@types\node\ts4.8\assert.d.ts
468 0
|
7月前
报错/ ./node_modules/axios/lib/platform/index.js Module parse failed: Unexpected token (5:2)怎么解决?
报错/ ./node_modules/axios/lib/platform/index.js Module parse failed: Unexpected token (5:2)怎么解决?
AxiosError: Network Error at XMLHttpRequest.handleError (webpack-internal:///./node_modules/axio
AxiosError: Network Error at XMLHttpRequest.handleError (webpack-internal:///./node_modules/axio
Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs extension.
Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs extension.
|
资源调度
Cannot find module ‘\node_modules\ejs\postinstall.js
Cannot find module ‘\node_modules\ejs\postinstall.js
143 0
|
JavaScript
Node.js Error: Cannot find module express
Node.js Error: Cannot find module express
123 1
node Express.js node:internal/modules/cjs/loader:988 throw err; ^ Error: Cannot find module ‘
node Express.js node:internal/modules/cjs/loader:988 throw err; ^ Error: Cannot find module ‘
1124 0
node Express.js node:internal/modules/cjs/loader:988 throw err; ^ Error: Cannot find module ‘
【Error】This dependency was not found: * core-js/modules/es.error.cause.js in ./node_modules/@babel
【Error】This dependency was not found: * core-js/modules/es.error.cause.js in ./node_modules/@babel
|
JavaScript Cloud Native Go
Error: Cannot find module ‘webpack/bin/config-yargs‘ at Function.Module._resolveFilename (intern
Error: Cannot find module ‘webpack/bin/config-yargs‘ at Function.Module._resolveFilename (intern
78 0