Git Product home page Git Product logo

vite-plugin-legacy-swc's People

Contributors

cyansalt avatar k-yle avatar modyqyw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

modyqyw

vite-plugin-legacy-swc's Issues

Types not exported, causing issues with NodeNext

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

It seems like the "types" export is missing, causing issues with typescript when using moduleResolution: "NodeNext"

Here is the diff that solved my problem:

diff --git a/node_modules/vite-plugin-legacy-swc/package.json b/node_modules/vite-plugin-legacy-swc/package.json
index 62cbde3..f35c247 100644
--- a/node_modules/vite-plugin-legacy-swc/package.json
+++ b/node_modules/vite-plugin-legacy-swc/package.json
@@ -8,6 +8,7 @@
   "types": "./dist/index.d.ts",
   "exports": {
     ".": {
+      "types": "./dist/index.d.ts",
       "import": "./dist/index.mjs",
       "require": "./dist/index.cjs"
     }

This issue body was partially generated by patch-package.

esm/commonjs import issue

Trying to import this legacy plugin like so

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import legacy from "vite-plugin-legacy-swc";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react(), legacy()],
});

causes the following error:

~/src/vite-project  master โœ”                                                                                                                                                                          โ—’  
โ–ถ yarn build                                             
yarn run v1.22.19
$ tsc && vite build
failed to load config from /home/bjorn/src/vite-project/vite.config.ts
error during build:
TypeError: legacy is not a function
    at file:///home/bjorn/src/vite-project/vite.config.ts.timestamp-1676562433105.mjs:6:22
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async loadConfigFromBundledFile (file:///home/bjorn/src/vite-project/node_modules/vite/dist/node/chunks/dep-3007b26d.js:62302:21)
    at async loadConfigFromFile (file:///home/bjorn/src/vite-project/node_modules/vite/dist/node/chunks/dep-3007b26d.js:62187:28)
    at async resolveConfig (file:///home/bjorn/src/vite-project/node_modules/vite/dist/node/chunks/dep-3007b26d.js:61808:28)
    at async build (file:///home/bjorn/src/vite-project/node_modules/vite/dist/node/chunks/dep-3007b26d.js:44492:20)
    at async CAC.<anonymous> (file:///home/bjorn/src/vite-project/node_modules/vite/dist/node/cli.js:813:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

In order to make it work, you have to do this

import legacyPkg from 'vite-plugin-legacy-swc'
// @ts-expect-error the package type definition is wrong
const legacy = legacyPkg.default as typeof legacyPkg

Steps to recreate:

$ yarn create vite
$ # Select React, Typescript + swc
$ yarn add -D vite-plugin-legacy-swc
$ # Edit vite.config.ts to match the first one in this issue
$ yarn build

Node version: v18.12.0

Packaging will generate two sets of codes

Packaging will generate two sets of codes, one is for modern browsers, and the other is code that is compatible with lower versions. How to set up to generate only one set of code that is compatible with lower versions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.