在写demo时,装了下t-design-vue2
的框架,想做个按需加载,官网这样说
但是我运行以后发现报错了
Error: Cannot find module 'node:module'
Require stack:
- D:\ruanjian\nvm\v19.0.0\xiangmu\niu789\niu789\node_modules\[email protected]@mlly\dist\index.cjs
摸不着头脑的那种
后来发现是默认安装的版本太高了,锁定版本:
//package.json
"devDependencies":{
"unplugin-auto-import": "^0.7.1",
"unplugin-vue-components": "^0.19.3",
}
然后再运行又报了另外一个错:
Invalid options in vue.config.js: "plugins" is not allowed
百度后说vue.config.js
里的plugin项要写到configureWebpack
里去,遂解决
main.js
:
import VueCompositionAPI from '@vue/composition-api'
// 引入组件库的少量全局样式变量
import 'tdesign-vue/es/style/index.css'
Vue.use(VueCompositionAPI) // 必须是项目的第一个 use
config.js
:
const { defineConfig } = require('@vue/cli-service')
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { TDesignResolver } = require('unplugin-vue-components/resolvers')
module.exports = defineConfig({
transpileDependencies: true,
configureWebpack: {
plugins: [
AutoImport({
resolvers: [TDesignResolver()]
}),
Components({
resolvers: [TDesignResolver()]
})
]
}
})
以上。
标签:node,vue,module,js,unplugin,plugins,import From: https://www.cnblogs.com/hjk1124/p/17744804.html