babel icon indicating copy to clipboard operation
babel copied to clipboard

[Bug]: Package "exports" field stripped on publishing

Open marvinhagemeister opened this issue 2 years ago • 6 comments

💻

  • [ ] Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

None, this is an error with the babel's publishing process.

Configuration file name

No response

Configuration

No response

Current and expected behavior

The development entry point of the @babel/transform-plugin-react-jsx cannot be imported in ESM environments because the exports field is missing in the published package. It's present in the source though, so I'm assuming that this is a publishing error.

Due to the missing field it not possible to load the development.js entry point.

Environment

  • Babel version: 7.18.10
  • Node: 18.7.0
  • Yarn: 1.22.17
  • OS: macOS 12.5.1

Possible solution

No response

Additional context

No response

marvinhagemeister avatar Aug 27 '22 13:08 marvinhagemeister

Hey @marvinhagemeister! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

babel-bot avatar Aug 27 '22 13:08 babel-bot

We cannot publish "exports" yet for backward compatibility (when publishing in non-Babel-8 mode, it's set to null). You can use @babel/plugin-transform-react-jsx-development instead.

nicolo-ribaudo avatar Aug 27 '22 14:08 nicolo-ribaudo

TIL, I didn't know about that package. Switched to that, but I can't get it to work either. Node still sees the ./lib/development.js require call in that package and errors.

marvinhagemeister avatar Aug 27 '22 15:08 marvinhagemeister

That is a cjs-to-cjs require, I don't see why Node.js would error 🤔

nicolo-ribaudo avatar Aug 27 '22 15:08 nicolo-ribaudo

Ok so I couldn't reproduce it with node in isolation, but something in a test project which uses astro + vite the error reliably occurs.

Here is the stack trace:

 error   Package subpath './lib/development' is not defined by "exports" in /project/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@babel/plugin-transform-react-jsx/package.json
  File:
    /project/src/components/Foo.jsx
  Stacktrace:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/development' is not defined by "exports" in /project/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@babel/plugin-transform-react-jsx/package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:335:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:560:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:94:18)
    at Object.<anonymous> (/project/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@babel/plugin-transform-react-jsx-development/lib/index.js:13:20)

marvinhagemeister avatar Aug 27 '22 17:08 marvinhagemeister

Can you check if project/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@babel/plugin-transform-react-jsx/package.json contains an exports field?

Do you know if something in your build setup rewrites CJS files to ESM while executing them?

nicolo-ribaudo avatar Aug 27 '22 19:08 nicolo-ribaudo

I'll close it due to long periods of inactivity, feel free to open it if the problem persists.

liuxingbaoyu avatar Sep 23 '22 13:09 liuxingbaoyu

The issue still exists, but I haven't had time to follow up. The package.json doesn't contain the exports field.

marvinhagemeister avatar Sep 23 '22 16:09 marvinhagemeister

The package.json doesn't contain the exports field.

That's expected and it's known to not cause problems, most of the packages on npm don't contain the exports field.

nicolo-ribaudo avatar Sep 24 '22 07:09 nicolo-ribaudo

@marvinhagemeister Any update on this? Do you have a reproduction (even not minimal)?

nicolo-ribaudo avatar Oct 10 '22 16:10 nicolo-ribaudo