[vite]:Rollup failed to resolve import "enutui/nutui/
我找了个开源项目,本地可以正常打包。但是想部署到线上环境。在线上的jenkins中,打包就不行。报错了:
里面有3个主要报错信息:
引用 error:Rollup failed to resolve import "enutui/nutui/dist/packages/Button/index.scss"from "src/plugins/nutUI.ts".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
build.rollupoptions.external'[39m
引用[error】【31 merror during build:
Error:[vite]:Rollup failed to resolve import "enutui/nutui/dist/packages/Button/index.scss"from "sre/plugins/nutUI.ts".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
build.rollupoptions.external'
引用[error】【!】Error:unfinished hook action(s)on exit:
完整报错信息:
[1og】trueI1og]【36 mvite v2,9.10【32mbui1 ding for production.+·I36m【39m
[log]transforming...
I1og]【32m√【39m6 modules transformed.
[error][31m[vite]:Rollup failed to resolve import "enutui/nutui/dist/packages/Button/index.scss"from "src/plugins/nutUI.ts".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
build.rollupoptions.external'[39m
[error】【31 merror during build:
Error:[vite]:Rollup failed to resolve import "enutui/nutui/dist/packages/Button/index.scss"from "sre/plugins/nutUI.ts".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
build.rollupoptions.external'
at onRollupWarning (/var/jenkins_home/workspace/IAM/iam-h5/node_modules/vite/dist/node/chunks/dep-9e5491c9.js:41772:19)
at onwarn (/var/jenkins_home/workspace/IAM/iam-h5/node modules/vite/dist/node/chunks/dep-9e5491c9.js:41588:13)
at object.onwarn (/var/jenkins_home/workspace/IAM/iam-h5/node_modules/rollup/dist/shared/rollup.js:23124:13)
at ModuleLoader.handleResolveId (/var/jenkins_home/workspace/IAM/iam-h5/node_modules/rollup/dist/shared/rollup.js:22404:26)
at /var/jenkins_home/workspace/IAM/iam-h5/node_modules/rollup/dist/shared/rollup.js:22365:26
at processTicksAndRejections (node:internal/process/task_queues:96:5)[39m
[error】【!】Error:unfinished hook action(s)on exit:
(vite:load-fallback)load "/var/jenkins_home/workspace/IAM/iam-h5/node_modules/vue/dist/vue.runtime.esm-bundler.js"
(vite:load-fallback)load "/var/jenkins_home/workspace/IAM/iam-h5/sre/assets/font/iconfont.css"
(vite:load-fallback)load "/var/jenkins_home/workspace/IAM/iam-h5/src/assets/app.css"
(vite:esbuild)transform "/var/jenkins_home/workspace/IAM/iam-h5/src/router/index.ts"
(vite:esbuild)transform "/var/jenkins_home/workspace/IAM/iam-h5/sre/il8n/index.ts"
(vite:esbuild)transform "/var/jenkins_home/workspace/IAM/iam-h5/src/store/index.ts"
(vite:load-fallback)load "/var/jenkins_home/workspace/IAM/iam
不知道哪里错了?
"dependencies": { "@nutui/nutui": "^3.1.21",
"@vueuse/core": "8.6.0",
"@vueuse/integrations": "8.6.0",
"axios": "0.27.2",
"pinia": "^2.0.14",
"universal-cookie": "^4.0.4",
"vant": "^3.5.0",
"vue": "^3.2.36",
"vue-i18n": "^9.1.10",
"vue-router": "^4.0.15"
},
"devDependencies": {
"@types/node": "^17.0.40",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"@vitejs/plugin-legacy": "^1.8.2",
"@vitejs/plugin-vue": "^2.3.3",
"@vitejs/plugin-vue-jsx": "^1.3.10",
"consola": "^2.15.3",
"eruda": "^2.4.1",
"eslint": "^8.17.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-vue": "^9.1.0",
"husky": "8.0.1",
"lint-staged": "12.4.1",
"mockjs": "^1.1.0",
"postcss": "^8.4.14",
"postcss-html": "1.4.1",
"postcss-px-to-viewport-8-plugin": "^1.1.3",
"postcss-less": "^6.0.0",
"prettier": "^2.6.2",
"stylelint": "^14.8.5",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-recommended": "^7.0.0",
"stylelint-config-recommended-vue": "^1.4.0",
"stylelint-config-standard": "^25.0.0",
"stylelint-order": "^5.0.0",
"typescript": "^4.6.3",
"vite": "^2.9.9",
"vite-plugin-eruda-plus": "^1.0.1",
"vite-plugin-mock": "^2.9.6",
"vite-plugin-style-import": "^2.0.0",
"vue-eslint-parser": "^9.0.2",
"vue-tsc": "^0.36.1"
},
回答:
参考https://github.com/vbenjs/vit...提出的方案,解决方式如下:
createStyleImportPlugin({ // resolves: [NutuiResolve()],
libs: [
{
libraryName: '@nutui/nutui',
esModule: true,
resolveStyle: (name) => {
name = name.toLowerCase().replace('-', ''); //NutuiResolve官方版目前在linux会造成大小写不一致问题无法加载资源
return `@nutui/nutui/dist/packages/${name}/index.scss`;
},
},
],
}),
问题主要是没有处理驼峰问题。issue中只处理大小写还不行,还需要去掉减号。
以上是 [vite]:Rollup failed to resolve import "enutui/nutui/ 的全部内容, 来源链接: utcz.com/p/944502.html