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

Broken legacy build #2471

Closed
Eazymov opened this issue Mar 11, 2021 · 6 comments
Closed

Broken legacy build #2471

Eazymov opened this issue Mar 11, 2021 · 6 comments

Comments

@Eazymov
Copy link

Eazymov commented Mar 11, 2021

Describe the bug

Building with plugin-legacy seems to be broken

Reproduction

  1. create new project with yarn create @vitejs/app (template - react + ts)
  2. add @vitejs/plugin-legacy - yarn add -D @vitejs/plugin-legacy
  3. update vite.config.ts -
import { defineConfig } from 'vite';
import legacy from '@vitejs/plugin-legacy';
import reactRefresh from '@vitejs/plugin-react-refresh';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [legacy(), reactRefresh()],
});
  1. run yarn build // error

System Info

  • vite version: 2.0.5
  • Operating System: Windows 10
  • Node version: 14.15.5
  • Package manager (npm/yarn/pnpm) and version: yarn@1.22.10

Logs (Optional if provided reproduction)

  1. Run vite build with the --debug flag.
$ tsc && vite build --debug
  vite:config bundled config file loaded in 201ms +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'alias',
  vite:config     'react-refresh',
  vite:config     'vite:dynamic-import-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'legacy-generate-polyfill-chunk',
  vite:config     'legacy-env',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:build-html',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'rollup-plugin-dynamic-import-variables',
  vite:config     'legacy-post-process',
  vite:config     'vite:import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:terser',
  vite:config     'vite:reporter'
  vite:config   ],
  vite:config   build: {
  vite:config     target: [ 'es2019', 'edge16', 'firefox60', 'chrome61', 'safari11' ],
  vite:config     polyfillDynamicImport: true,
  vite:config     outDir: 'dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     sourcemap: false,
  vite:config     rollupOptions: { output: [Array] },
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     minify: 'terser',
  vite:config     terserOptions: {},
  vite:config     cleanCssOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     brotliSize: true,
  vite:config     chunkSizeWarningLimit: 500
  vite:config   },
  vite:config   define: { 'import.meta.env.LEGACY': '__VITE_IS_LEGACY__' },
  vite:config   configFile: 'C:/Users/azymov/Documents/projects/vite-project/vite.config.ts',
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     build: {}
  vite:config   },
  vite:config   root: 'C:/Users/azymov/Documents/projects/vite-project',
  vite:config   base: '/',
  vite:config   resolve: { dedupe: undefined, alias: [ [Object] ] },
  vite:config   publicDir: 'C:\\Users\\azymov\\Documents\\projects\\vite-project\\public',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   isProduction: true,
  vite:config   optimizeCacheDir: 'C:\\Users\\azymov\\Documents\\projects\\vite-project\\node_modules\\.vite',
  vite:config   server: {},
  vite:config   env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen]
  vite:config   },
  vite:config   createResolver: [Function: createResolver]
  vite:config } +5ms
vite v2.0.5 building for production...
✓ 21 modules transformed.
[legacy-post-process] [BABEL] unknown: .plugins[36][0] must be a string, object, function
error during build:
Error: [BABEL] unknown: .plugins[36][0] must be a string, object, function
    at assertPluginTarget (C:\Users\azymov\Documents\projects\vite-project\node_modules\@babel\standalone\babel.js:67416:12)
    at assertPluginItem (C:\Users\azymov\Documents\projects\vite-project\node_modules\@babel\standalone\babel.js:67390:6)
    at C:\Users\azymov\Documents\projects\vite-project\node_modules\@babel\standalone\babel.js:67373:15
    at Array.forEach (<anonymous>)
    at assertPluginList (C:\Users\azymov\Documents\projects\vite-project\node_modules\@babel\standalone\babel.js:67372:10)
    at C:\Users\azymov\Documents\projects\vite-project\node_modules\@babel\standalone\babel.js:67591:6
    at Array.forEach (<anonymous>)
    at validateNested (C:\Users\azymov\Documents\projects\vite-project\node_modules\@babel\standalone\babel.js:67567:22)
    at validate$3 (C:\Users\azymov\Documents\projects\vite-project\node_modules\@babel\standalone\babel.js:67558:11)
    at C:\Users\azymov\Documents\projects\vite-project\node_modules\@babel\standalone\babel.js:69754:15
  1. Provide the error log here.
$ tsc && vite build
vite v2.0.5 building for production...
✓ 21 modules transformed.
[legacy-post-process] [BABEL] unknown: .plugins[36][0] must be a string, object, function
error during build:
Error: [BABEL] unknown: .plugins[36][0] must be a string, object, function
    at assertPluginTarget (C:\Users\azymov\Documents\projects\vite-project\node_modules\@babel\standalone\babel.js:67416:12)
    at assertPluginItem (C:\Users\azymov\Documents\projects\vite-project\node_modules\@babel\standalone\babel.js:67390:6)   
    at C:\Users\azymov\Documents\projects\vite-project\node_modules\@babel\standalone\babel.js:67373:15
    at Array.forEach (<anonymous>)
    at assertPluginList (C:\Users\azymov\Documents\projects\vite-project\node_modules\@babel\standalone\babel.js:67372:10)  
    at C:\Users\azymov\Documents\projects\vite-project\node_modules\@babel\standalone\babel.js:67591:6
    at Array.forEach (<anonymous>)
    at validateNested (C:\Users\azymov\Documents\projects\vite-project\node_modules\@babel\standalone\babel.js:67567:22)    
    at validate$3 (C:\Users\azymov\Documents\projects\vite-project\node_modules\@babel\standalone\babel.js:67558:11)
    at C:\Users\azymov\Documents\projects\vite-project\node_modules\@babel\standalone\babel.js:69754:15
@Eazymov
Copy link
Author

Eazymov commented Mar 11, 2021

Looks like duplicate of #2442, but this solution doesn't work in the described case.

@pedrodim
Copy link
Contributor

pedrodim commented Mar 11, 2021

@Eazymov since you're using yarn, as a temporal workaround similar to the one on #2442, you can try and use selective resolution to pin the version. https://classic.yarnpkg.com/en/docs/selective-version-resolutions/#toc-how-to-use-it

@dejour
Copy link
Contributor

dejour commented Mar 11, 2021

It seems like a bug in @babel/standalone. After looked the source code, i found below code caused the bug.

var pluginCoreJS2 = _pluginCoreJS2["default"];
var pluginCoreJS3 = _pluginCoreJS3["default"];
var pluginRegenerator$1 = _pluginRegenerator$1["default"];

all these variable are undefined. after changed to following format

var pluginCoreJS2 = _pluginCoreJS2;
var pluginCoreJS3 = _pluginCoreJS3;
var pluginRegenerator$1 = _pluginRegenerator$1;

the errors are gone.

@dejour
Copy link
Contributor

dejour commented Mar 11, 2021

the code path trace back to @vitejs/plugin-legacy's this option

useBuiltIns: needPolyfills ? 'usage' : false

@Eazymov
Copy link
Author

Eazymov commented Mar 11, 2021

@Eazymov since you're using yarn, as a temporal workaround similar to the one on #2442, you can try and use selective resolution to pin the version. https://classic.yarnpkg.com/en/docs/selective-version-resolutions/#toc-how-to-use-it

Thanks, this solved my problem!

@patak-dev
Copy link
Member

Closing as duplicate of #2442

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants