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

require is not defined when using Lazy Loading Routes by vue-router #4746

Closed
7 tasks done
shenX-2021 opened this issue Aug 26, 2021 · 11 comments · Fixed by #5132
Closed
7 tasks done

require is not defined when using Lazy Loading Routes by vue-router #4746

shenX-2021 opened this issue Aug 26, 2021 · 11 comments · Fixed by #5132
Labels
documentation Improvements or additions to documentation

Comments

@shenX-2021
Copy link

shenX-2021 commented Aug 26, 2021

Describe the bug

use Lazy Loading Routes by vue-router like the below code,

// router.js
createRouter({
  history: createWebHashHistory('/'),
  routes: [
    {
      path: '/',
      name: 'Home',
      component: () => import('/src/views/Home.vue')
    }
  ]
});
vite.config.js
export default defineConfig({
  // ...
  build: {
    target: ['chrome61']
  },
})

it is error console in browser

vendor.dcd75cb2.js:6 ReferenceError: require is not defined
    at index.a463ca0d.js:1

Reproduction

https://github.com/gxsandzxl/vite-bug-demo

System Info

System:
    OS: Windows 10 10.0.17763
    CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
    Memory: 3.63 GB / 11.88 GB
  Binaries:
    Node: 12.16.2 - D:\Program Files\node\node.EXE
    Yarn: 1.22.10 - D:\Program Files\node\npm_global\yarn.CMD
    npm: 7.16.0 - D:\Program Files\node\npm.CMD
  Browsers:
    Chrome: 92.0.4515.159
    Edge: Spartan (44.17763.831.0)
    Internet Explorer: 11.0.17763.771
  npmPackages:
    @vitejs/plugin-vue: ^1.6.0 => 1.6.0
    vite: ^2.5.1 => 2.5.1

Used Package Manager

npm

Logs

No response

Validations

@Ttou
Copy link

Ttou commented Aug 26, 2021

may be affected by this issue #3469

@haoqunjiang
Copy link
Member

chrome61 requires plugin-legacy.
The build.target documentation isn't in sync with the "Browser Compatibility" section, though. Needs to be fixed.

@haoqunjiang haoqunjiang added documentation Improvements or additions to documentation and removed pending triage labels Aug 26, 2021
@shenX-2021
Copy link
Author

@sodatea Actually, my purpose is preventing css rgba transform to hex color style. I make some try
if using plugin-legacy, Minify will transform rgba to hex color style.
if using build: { target: ['chrome61'] }, dynamic import will cause this issue.

if it is not a bug, how to achieve my purpose.

@haoqunjiang
Copy link
Member

Could you please provide a reproduction?
And what exact browser targets are you aiming at?

@shenX-2021
Copy link
Author

https://github.com/gxsandzxl/vite-bug-demo
android wechat browser, it does't support rrggbbaa style

@Ttou
Copy link

Ttou commented Aug 27, 2021

@sodatea
vite 2.5.0 use esbuild to minify css, this will transform rgba to rrggbbaa, android webview can't support it;
vite 2.5.1 fix color transform with set target with chrome61, but this will cause an other error: require is not defined

@haoqunjiang
Copy link
Member

haoqunjiang commented Aug 27, 2021

That's a quirk in Android WeChat WebView (or to say, Tencent X5, because Android QQ Browser has this issue too).

I can't find any other browser that supports native dynamic imports but not RGBA hex color…


There's no easy way to work around this issue at the moment.
esbuild only supports mainstream browsers as its target. None of them share the same quirk as Tencent X5.

So please:

  1. Disable minify completely and set up your own JS/CSS minification tools;
  2. Or, downgrade to Vite 2.4, set build.cleanCssOptions to disable compatibility.colors.hexAlpha (seems to be disabled by default)

@haoqunjiang haoqunjiang added p3-minor-bug An edge case that only affects very specific usage (priority) and removed p3-minor-bug An edge case that only affects very specific usage (priority) labels Aug 27, 2021
@shenX-2021
Copy link
Author

That's a quirk in Android WeChat WebView (or to say, Tencent X5, because Android QQ Browser has this issue too).

I can't find any other browser that supports native dynamic imports but not RGBA hex color…

There's no easy way to work around this issue at the moment.
esbuild only supports mainstream browsers as its target. None of them share the same quirk as Tencent X5.

So please:

  1. Disable minify completely and set up your own JS/CSS modification tools;
  2. Or, downgrade to Vite 2.4, set build.cleanCssOptions to disable compatibility.colors.hexAlpha (seems to be disabled by default)

all right, thanks a lot

@Ttou
Copy link

Ttou commented Aug 27, 2021

@sodatea Is it possible to provide an property for minify css: 'esbuild' or 'clean-css' ?

@Shinigami92
Copy link
Member

@Ttou Exactly that
In today Vite Meeting we discussed that we want an option for build.cssMinifyTarget + some good documentation what it is doing and when it is needed

@xkelvinx666
Copy link

That's a quirk in Android WeChat WebView (or to say, Tencent X5, because Android QQ Browser has this issue too).

I can't find any other browser that supports native dynamic imports but not RGBA hex color…

There's no easy way to work around this issue at the moment. esbuild only supports mainstream browsers as its target. None of them share the same quirk as Tencent X5.

So please:

1. Disable `minify` completely and set up your own JS/CSS minification tools;

2. Or, downgrade to Vite 2.4, set [`build.cleanCssOptions`](https://vitejs.dev/config/#build-cleancssoptions) to disable [`compatibility.colors.hexAlpha`](https://github.com/clean-css/clean-css#compatibility-modes) (seems to be disabled by default)

There is the changelog about why rgba to hex esbuild hex docs. Accroding to this docs, I try to set target at 'chrome51', it will not change rgba to hex

haoqunjiang added a commit to haoqunjiang/vite that referenced this issue Sep 29, 2021
patak-dev pushed a commit that referenced this issue Oct 9, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Oct 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants