mohebifar / react-unforget

DEPRECATED | ⚠️ Use React Compiler instead ⚠️ | A compiler for automatic optimization of React apps
https://react-unforget.vercel.app/
MIT License
391 stars 4 forks source link

Incorrect package.json `exports` field for @react-unforget/runtime #22

Closed ceopaludetto closed 4 months ago

ceopaludetto commented 4 months ago

I was trying to use react-unforget in a simple vite application, so I did the following configuration:

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

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react({ babel: { plugins: ["@react-unforget/babel-plugin"] } }),
  ],
});

When I've started the dev server, I got the following error: Error: [commonjs--resolver] Failed to resolve entry for package "@react-unforget/runtime". The package may have incorrect main/module/exports specified in its package.json.

So, after some investigation I've discovered that you published the package.json with the following entries:

"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"exports": {
  "require": "./dist/index.js",
  "import": "./dist/index.mjs",
  "types": "./dist/index.d.ts"
},

But in the dist folder, the modules are swapped(js -> cjs, mjs -> js) and the types section is after require or import, so I suggest the following changes:

"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
  "import": {
    "types": "./dist/index.d.ts",
    "default": "./dist/index.js"
  },
  "require": {
    "types": "./dist/index.d.cts",
    "default": "./dist/index.cjs"
  }
},

After this modification, everything works like a charm

mohebifar commented 4 months ago

@ceopaludetto Thanks for reporting the issue. And I'm glad to hear you were able to use Unforget in your project! I'm currently working on a partial re-write to make the compiler more robust. I'm looking fro early adapters to test it and report bugs / provide feedback. Are you interested in contributing by reporting issues?