-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webpack / Vue CLI: defineOptions is not defined
(production mode)
#23
Comments
Please provide a reproduction repo. |
This is the project repo: https://github.com/ShaneLee-9/vue-define-options-demo |
同样遇到,解决了吗 |
用于webpack下暂时有点问题 |
如何在typescript下定义d.ts声明 |
@ShaneLee-9 @wangshuai0 似乎是与 babel 一起用的时候会出问题,尝试去掉 babel 试试 |
有合适的解决方案么?我在dev环境没有问题,build完在生产环境出现了这个报错. |
暂无解决方法,等上游修复 |
|
You can set Related: |
defineOptions is not defined
(production mode)
我用vite也是生产环境not defined,但dev环境没问题 |
发现把node_modules删掉,重新install,马上再build就不会有问题, 但是偶尔关机或者重启编辑器可能就会再次报错! |
尝试上面提到的方法。 |
"0.8.0" 在 vite中存在相同问题, 回退到"0.7.3"版本正常, |
@sxzz 似乎类型文件地址错了https://unpkg.com/browse/unplugin-vue-define-options@0.8.2/package.json https://github.com/ckvv/vite-project-unplugin-vue-macros
|
@ckvv 没问题的,因为使用了别名
|
是的,我用最新版[0.11.2]也出现报错的情况,在回退到0.7.3之后便正常了。 vscode报错信息
然后我发现: import * as unplugin from 'unplugin';
export { transform } from './core/transform.js';
import { defineComponent } from 'vue';
import { FilterPattern } from '@rollup/pluginutils';
import '@vue/compiler-sfc';
declare global {
const defineOptions: typeof defineComponent;
}
interface Options {
include?: FilterPattern;
exclude?: FilterPattern | undefined;
}
declare type OptionsResolved = Required<Options>;
declare const _default: unplugin.UnpluginInstance<Options>;
export { Options, OptionsResolved, _default as default }; 而0.11.2版本的 unplugin-vue-define-options/index.d.ts 是这样的: import * as unplugin from 'unplugin';
export { transform } from './core/transform.js';
import { FilterPattern } from '@rollup/pluginutils';
interface Options {
include?: FilterPattern;
exclude?: FilterPattern;
}
declare type OptionsResolved = Omit<Required<Options>, 'exclude'> & {
exclude?: FilterPattern;
};
declare const _default: unplugin.UnpluginInstance<Options | undefined>;
export { Options, OptionsResolved, _default as default }; 似乎是类型文件缺少了定义 下面是我的项目依赖: {
"dependencies": {
"@dcloudio/uni-app": "3.0.0-alpha-3050320220727002",
"@dcloudio/uni-app-plus": "3.0.0-alpha-3050320220727002",
"@dcloudio/uni-components": "3.0.0-alpha-3050320220727002",
"@dcloudio/uni-h5": "3.0.0-alpha-3050320220727002",
"@dcloudio/uni-mp-alipay": "3.0.0-alpha-3050320220727002",
"@dcloudio/uni-mp-baidu": "3.0.0-alpha-3050320220727002",
"@dcloudio/uni-mp-kuaishou": "3.0.0-alpha-3050320220727002",
"@dcloudio/uni-mp-lark": "3.0.0-alpha-3050320220727002",
"@dcloudio/uni-mp-qq": "3.0.0-alpha-3050320220727002",
"@dcloudio/uni-mp-toutiao": "3.0.0-alpha-3050320220727002",
"@dcloudio/uni-mp-weixin": "3.0.0-alpha-3050320220727002",
"@dcloudio/uni-quickapp-webview": "3.0.0-alpha-3050320220727002",
"pinia": "^2.0.20",
"vue": "^3.2.37",
"vue-i18n": "^9.1.9",
"vuex": "^4.0.2"
},
"devDependencies": {
"@dcloudio/types": "^3.0.7",
"@dcloudio/uni-automator": "3.0.0-alpha-3050320220727002",
"@dcloudio/uni-cli-shared": "3.0.0-alpha-3050320220727002",
"@dcloudio/uni-stacktracey": "3.0.0-alpha-3050320220727002",
"@dcloudio/vite-plugin-uni": "3.0.0-alpha-3050320220727002",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/eslint-config-standard": "^5.1.2",
"@vue/eslint-config-typescript": "^7.0.0",
"eslint": "^6.7.2",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^7.0.0",
"postcss-html": "^1.3.0",
"postcss-scss": "^4.0.3",
"sass": "^1.54.5",
"stylelint": "^14.5.3",
"stylelint-config-html": "^1.0.0",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-standard": "^25.0.0",
"stylelint-order": "^5.0.0",
"stylelint-scss": "^4.1.0",
"typescript": "^4.7.4",
"unplugin-vue-define-options": "^0.11.2",
"vite": "^2.9.14"
}
} |
最新版需要手动配置 // tsconfig.json
{
"compilerOptions": {
// ...
"types": ["unplugin-vue-define-options/macros-global" /* ... */]
}
} |
I have a minimal webpack config: const VueLoaderPlugin = require('vue-loader/lib/plugin');
const defineOptions = require('unplugin-vue-define-options/webpack');
const nodeExternals = require('webpack-node-externals');
module.exports = {
mode: 'development',
entry: './test.vue',
externals: [nodeExternals()],
module: {
rules: [
{
test: /\.vue$/,
use: [
{
loader: 'vue-loader',
},
],
},
],
},
plugins: [new VueLoaderPlugin(), defineOptions()],
devtool: false,
}; the configuration above can not work, unless I add a loader {
loader: 'unplugin/dist/webpack/loaders/transform?unpluginName=unplugin-vue-define-options',
} the full configuration is: const VueLoaderPlugin = require('vue-loader/lib/plugin');
const defineOptions = require('unplugin-vue-define-options/webpack');
const nodeExternals = require('webpack-node-externals');
module.exports = {
mode: 'development',
entry: './test.vue',
externals: [nodeExternals()],
module: {
rules: [
{
test: /\.vue$/,
use: [
{
loader: 'vue-loader',
},
{
loader:
'unplugin/dist/webpack/loaders/transform?unpluginName=unplugin-vue-define-options',
},
],
},
],
},
plugins: [new VueLoaderPlugin(), defineOptions()],
devtool: false,
}; I have create a StackBlitz demo, the link: https://stackblitz.com/edit/node-fu77mv?file=package.json,index.js,test.vue,webpack.config.js,dist%2Fmain.js you can run you can see, without this loader, the |
@qinyang912 Thanks for your feedback! For Vue 2 (Vue loader 15) + Webpack, an additional option is required. plugins: [
defineOptions({
include: [/\.vue$/, /\.vue\?vue/],
}),
new VueLoaderPlugin(),
], I will add it to the documentation later. |
请问目前有解决办法了么。同为webpack5报错,显示 defineOptions is not defined |
vue 3 defineOptions({
include: [/\.vue$/, /\.vue\?vue/],
}) |
@Nstd |
@ShaneLee-9 你用的啥环境(版本)?配置文件看看 |
@Nstd 这是仓库地址:https://github.com/ShaneLee-9/vue-options-plugin-test 开发环境打包后 |
@Nstd 对了, |
@ShaneLee-9 需要再加个一个配置: |
@Nstd 有用! |
我也遇到了,咋整 |
You can use |
dependencies:
"vue": "^3.2.13",
"unplugin-vue-define-options": "^0.6.1",
”webpack": "5.70.0"
vue.config.js
config:The text was updated successfully, but these errors were encountered: