question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

plugin-legacy:Unexpected token import

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
TobiasMelencommented, Apr 16, 2021

Needs PR. Since it seems to solve the issue i will add a one when i can, probably later today.

4reactions
TobiasMelencommented, Apr 15, 2021

Ok, so i found a way to fix it in our project. Moving the recording and removing of polyfills from Program:exit to post in the plugin lifecycle seems let all nodes finish processing before it’s executed. The theory being that while the custom plugins Program:exit is run after @babel/preset-envs Program:exit there might still be AST-nodes left to process adding polyfills. https://jamie.build/babel-plugin-ordering.html

Since 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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found