plugin-legacy:Unexpected token import
See original GitHub issueDescribe the bug
I used the plugin @vitejs/plugin-legacy
legacy({
targets: ['chrome 53']
}),
But the packaged code still contains import"core-js/modules/es.promise.js";
****-legacy.278fab9b.js:1 Uncaught SyntaxError: Unexpected token import
SyntaxError: Unexpected token import
****-legacy.278fab9b.js:1 Uncaught (in promise) SyntaxError: Unexpected token import
Reproduction
When some components are split into a single file In fact, I can’t reproduce this bug with the least amount of code
System Info
System:
OS: Windows 10 10.0.19042
CPU: (8) x64 AMD Ryzen 5 2500U with Radeon Vega Mobile Gfx
Memory: 998.52 MB / 6.90 GB
Binaries:
Node: 14.15.3 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
npm: 6.14.9 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 87.0.4280.88
Edge: Spartan (44.19041.423.0), Chromium (89.0.774.63)
Internet Explorer: 11.0.19041.1
npmPackages:
@vitejs/plugin-vue: ^1.1.5 => 1.2.0
vite: ^2.1.4 => 2.1.4
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:8 (6 by maintainers)
Top Results From Across the Web
SyntaxError: Unexpected token import- Node.js - Stack Overflow
I am trying to code split my app with webpack but webpack is not creating the chunks for my dynamic imports.
Read more >typescript syntaxerror: unexpected token 'export' - You.com
So the dependency in node_modules folder exports a function using ES6 import/export module. The code will throw error when it running in browser...
Read more >How to solve the 'SyntaxError: Unexpected token' issue
To resolve the issue, we can replace the main entry point of `pdfjs-dist` with its legacy path. Update the Worker path. import {...
Read more >Module parse failed: Unexpected token Emberjs - Build Issues
Module parse failed: Unexpected token Emberjs ... @ts-nocheck import ts from 'rollup-plugin-ts'; import { Addon } from ...
Read more >Using Plugins - Vite
vite.config.js import legacy from '@vitejs/plugin-legacy' import { defineConfig } from 'vite' export default defineConfig({ plugins: [ legacy({ targets: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Needs PR. Since it seems to solve the issue i will add a one when i can, probably later today.
Ok, so i found a way to fix it in our project. Moving the recording and removing of polyfills from
Program:exit
topost
in the plugin lifecycle seems let all nodes finish processing before it’s executed. The theory being that while the custom pluginsProgram:exit
is run after@babel/preset-env
sProgram:exit
there might still be AST-nodes left to process adding polyfills. https://jamie.build/babel-plugin-ordering.htmlSince this is hard to reproduce it would be great with proof this actually fixes the issue before PR. @fnlctrl, @vibo and/or @rashagu: Could you try adding https://github.com/TobiasMelen/vite/blob/record-remove-polyfills-post/packages/plugin-legacy/index.js to a seperate js file and importing the plugin from that local file instead and then test if builds strip all
import
statements?