Skip to content
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

开启了 transformMixedEsModules: true, vite preview 依然报错 - require 是动态引入 #43

Open
haiting opened this issue Dec 13, 2022 · 3 comments

Comments

@haiting
Copy link

haiting commented Dec 13, 2022

开启了 transformMixedEsModules: true, require 动态引入文件, vite preview 依然报错

  • 开启 transformMixedEsModules
    build: {
    commonjsOptions: {
    transformMixedEsModules: true
    },
    },
  • js文件内容
if (a) {
    require('a.js');
    require('b.scss');
}

if (b) {
    require(c.js');
}

或者:

function registeredLayoutStore() {
  return {
    state: require('./store/state').default,
    actions: require('./store/actions').default,
    getters: require('./store/getters').default,
    mutations: require('./store/mutations').default
  };
}
  • run pnpm build
  • run pnpm preview
  • 错误如下:
Uncaught ReferenceError: require is not defined

Originally posted by @u373693041 in #9 (comment)

@haiting haiting changed the title 开启了 transformMixedEsModules: true, vite preview依然报错 开启了 transformMixedEsModules: true, vite preview 依然报错 - require 是动态引入 Dec 13, 2022
@wmo123
Copy link

wmo123 commented Feb 11, 2023

请问问题解决了吗?

@haiting
Copy link
Author

haiting commented Mar 28, 2023

registeredLayoutStore

没呢,改了代码引用方式

export function useLayoutStoreWithOut() {
  return {
    state: { ...state },
    actions: { ...actions },
    getters: { ...getters },
    mutations: { ...mutations }
  };
}

@JasonBoy
Copy link

JasonBoy commented Sep 6, 2023

动态改静态我也不行 🤦 ,第三方ui库,vue组件里混着写。。。,或者能让这插件支持build么?
CleanShot 2023-09-06 at 16 56 46@2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants