在微信云托管上部署遭遇的bug 日志如下
[2022-05-16 18:01:08] [vite]: Rollup failed to resolve import "axios" from "src/api/request.js".
[2022-05-16 18:01:08] This is most likely unintended because it can break your application at runtime.
[2022-05-16 18:01:08] If you do want to externalize this module explicitly add it to
[2022-05-16 18:01:08] `build.rollupOptions.external`
[2022-05-16 18:01:08] error during build:
[2022-05-16 18:01:08] Error: [vite]: Rollup failed to resolve import "axios" from "src/api/request.js".
[2022-05-16 18:01:08] This is most likely unintended because it can break your application at runtime.
[2022-05-16 18:01:08] If you do want to externalize this module explicitly add it to
[2022-05-16 18:01:08] `build.rollupOptions.external`
[2022-05-16 18:01:08] at onRollupWarning (/app/node_modules/vite/dist/node/chunks/dep-59dc6e00.js:41489:19)
[2022-05-16 18:01:08] at onwarn (/app/node_modules/vite/dist/node/chunks/dep-59dc6e00.js:41305:13)
[2022-05-16 18:01:08] at Object.onwarn (/app/node_modules/rollup/dist/shared/rollup.js:23184:13)
[2022-05-16 18:01:08] at ModuleLoader.handleResolveId (/app/node_modules/rollup/dist/shared/rollup.js:22474:26)
[2022-05-16 18:01:08] at /app/node_modules/rollup/dist/shared/rollup.js:22435:26
根据日志提示
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
将vue中vite的配置文件中添加
build:{
rollupOptions:{
external:['axios']
}
}
完整配置文件如下
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { quasar, transformAssetUrls } from '@quasar/vite-plugin'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue({
template: { transformAssetUrls }
}),
quasar({
sassVariables: 'src/quasar-variables.sass'
})
],
build:{
rollupOptions:{
external:['axios']
}
}
})
但是会导致axios不可用
所以正确的做法是将axios加入package.json的依赖中
"dependencies": {
"axios": "^0.27.2"
},
|