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

Legacy build fails on babel step #2442

Closed
pedrodim opened this issue Mar 9, 2021 · 17 comments · Fixed by #2649
Closed

Legacy build fails on babel step #2442

pedrodim opened this issue Mar 9, 2021 · 17 comments · Fixed by #2649
Labels
bug: upstream Bug in a dependency of Vite plugin: legacy

Comments

@pedrodim
Copy link
Contributor

pedrodim commented Mar 9, 2021

Describe the bug

The build with the legacy plugin active fails with an error from babel.

❯ npm run build

> vite-project@0.0.0 build
> tsc && vite build

vite v2.0.5 building for production...
✓ 21 modules transformed.
[legacy-post-process] [BABEL] unknown: .plugins[13][0] must be a string, object, function
error during build:
Error: [BABEL] unknown: .plugins[13][0] must be a string, object, function
    at assertPluginTarget (/Sites/vite-project/node_modules/@babel/standalone/babel.js:67416:12)
    at assertPluginItem (//Sites/vite-project/node_modules/@babel/standalone/babel.js:67390:6)
    at //Sites/vite-project/node_modules/@babel/standalone/babel.js:67373:15
    at Array.forEach (<anonymous>)
    at assertPluginList (/Sites/vite-project/node_modules/@babel/standalone/babel.js:67372:10)
    at /Sites/vite-project/node_modules/@babel/standalone/babel.js:67591:6
    at Array.forEach (<anonymous>)
    at validateNested (/Sites/vite-project/node_modules/@babel/standalone/babel.js:67567:22)
    at validate$3 (/Sites/vite-project/node_modules/@babel/standalone/babel.js:67558:11)
    at /Sites/vite-project/node_modules/@babel/standalone/babel.js:69754:15

Reproduction

Base config

import { defineConfig } from 'vite'
import legacy from '@vitejs/plugin-legacy'

export default defineConfig({
  plugins: [legacy({ targets: ['defaults', 'not IE 11'] })]
})

System Info

  • vite version: 2.0.5
  • Operating System: macOS Big Sur
  • Node version: 12.21.0
  • Package manager (npm/yarn/pnpm) and version: npm 7.6.0
@pedrodim
Copy link
Contributor Author

pedrodim commented Mar 9, 2021

Removing the env preset from legacy-post-process plugin causes the build to complete with success, so maybe something changed with how @babel/standalone handles the plugins? or the export from preset-env changed

@Ttou
Copy link

Ttou commented Mar 10, 2021

same problem

@mengelbrecht
Copy link

mengelbrecht commented Mar 10, 2021

As a temporary workaround you can pin the @babel/standalone version to 7.13.9 in package.json:

"@babel/standalone": "7.13.9"

@qmagics
Copy link

qmagics commented Mar 11, 2021

I had the same problem.

my vite.config.ts file

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import legacy from '@vitejs/plugin-legacy'

export default defineConfig({
  plugins: [
    vue(),
    legacy({
      targets: ['defaults', 'not IE 11']
    })
  ],

  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  },

  build: {
    outDir: "./www",
  }
})

@wgordon17
Copy link

wgordon17 commented Mar 13, 2021

@mengelbrecht Where exactly are we supposed to pin @babel/standalone? Since it looks like plugin-legacy vendors it's own version of @babel/standalone at ^7.12.12.

For those using yarn for their package manager, I got this working with

  "dependencies": {
    ...
  },
  "devDependencies": {
    ...
  },
  "resolutions": {
    "@vitejs/plugin-legacy/@babel/standalone": "7.13.9"
  }

@holtwick
Copy link

+1 having the same issue. @mengelbrecht 's workaround helped for now #2442 (comment)

@yyx990803 yyx990803 added bug: upstream Bug in a dependency of Vite plugin: legacy and removed pending triage labels Mar 15, 2021
@richard1015
Copy link

+1 having the same issue. @wgordon17 's workaround helped for now #2442(comment)

@lzm0x219
Copy link

so.. I use pnpm, it seems to have no effect.

@pedrodim
Copy link
Contributor Author

@vvni forn pnpm you should use a readPackage hook to change the version required by @vitejs/plugin-legacy

module.exports = {
  hooks: {
    readPackage: (pkg) => {
      if (pkg.name === "@vitejs/plugin-legacy") {
        pkg.dependencies['@babel/standalone'] = '7.13.9';
      }
      return pkg;
    }
  }
};

@lzm0x219
Copy link

@vvni forn pnpm you should use a readPackage hook to change the version required by @vitejs/plugin-legacy

module.exports = {
  hooks: {
    readPackage: (pkg) => {
      if (pkg.name === "@vitejs/plugin-legacy") {
        pkg.dependencies['@babel/standalone'] = '7.13.9';
      }
      return pkg;
    }
  }
};

thanks!

@zheeeng
Copy link
Contributor

zheeeng commented Mar 18, 2021

Is any progress there?

@ShookLyngs
Copy link

Any progress?
I'm also facing the issue right now...

@fwh1990
Copy link

fwh1990 commented Mar 22, 2021

@zheeeng @ShookLyngs You may waiting for PR from either babel/babel#13017 or rollup/plugins#838 .

@fwh1990
Copy link

fwh1990 commented Mar 23, 2021

@babel/standalone@7.13.12 has been published, RE-install vite-legacy can fix this issue.

yarn remove @vitejs/plugin-legacy && yarn add @vitejs/plugin-legacy --dev

@patak-dev
Copy link
Member

@pedrodim could you confirm that this issue has been fixed after @babel/standalone@7.13.12?

@pedrodim
Copy link
Contributor Author

pedrodim commented Mar 23, 2021

Yes! Issue is fixed with @babel/standalone@7.13.12.

It would be great if the plugin's package.json would be updated with the updated @babel/standalone version number, but not necessary as it picks already the correct version as it is thanks to semver

npm uninstall @babel/standalone @vitejs/plugin-legacy && npm install @vitejs/plugin-legacy -D

@patak-dev
Copy link
Member

@pedrodim would you like to send a PR for that?

@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.
Labels
bug: upstream Bug in a dependency of Vite plugin: legacy
Projects
None yet
Development

Successfully merging a pull request may close this issue.