Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: esbuild-plugin-pnp doesn't use module in package.json for libraries #3185

Closed
huvber opened this issue Jul 27, 2021 · 5 comments
Closed
Labels
bug Something isn't working upholded Real issues without formal reproduction

Comments

@huvber
Copy link

huvber commented Jul 27, 2021

Describe the bug

Even if in the building options of esbuild it's define module in the mainFields the plugin use always (and only main). This will create some problem because when building in esm or iife usually library put the umd (or commonjs) version in main and the esm one in modules.

To reproduce

One of the library that has this configuration in the package.json is swr
The following file can help to make a use case test

esbuild.js

const { pnpPlugin } = require('@yarnpkg/esbuild-plugin-pnp');
const esbuild = require('esbuild');

esbuild.build({
  entryPoints: {
    index: 'src/index.tsx',
    'index.html': 'src/index.html',
  },
  assetNames: '[name]',
  inject: ['./react-shim.js'],
  mainFields: ['module', 'main'],
  bundle: true,
  outdir: 'build',
  loader: {
    '.html': 'file',
    '.css': 'css',
  },
  plugins: [
    pnpPlugin(),
  ],
});

src/index.ts

import { render } from 'react-dom';
import useSWR from 'swr';

const App = () => {
  const result = useSWR('https://official-joke-api.appspot.com/random_joke');
  return (
    <section>
      <header>
        <h2>This is a test</h2>
      </header>
      <main>{result.data}</main>
    </section>
  );
};

render(<App />, document.querySelector('main'));

package.json

{
  "name": "esbuild-test",
  "sideEffects": false,
  "main": "build/index.js",
  "files": [
    "build"
  ],
  "scripts": {
    "build": "rm -rf build && yarn node esbuild.js"
  },
  "devDependencies": {
    "@types/react": "^17.0.13",
    "@types/react-dom": "^17",
    "@yarnpkg/esbuild-plugin-pnp": "^1.0.0-rc.13",
    "esbuild": "^0.12.16"
  },
  "dependencies": {
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "swr": "^0.5.6"
  }
}

Environment

OS: macOS
browser: chrome, firefox

Additional context

No response

@huvber huvber added the bug Something isn't working label Jul 27, 2021
@huvber
Copy link
Author

huvber commented Jul 30, 2021

Can you please take a look at this? I think it will be a problem for a lot of projects

@yarnbot
Copy link
Collaborator

yarnbot commented Aug 29, 2021

Hi! 👋

This issue looks stale, and doesn't feature the reproducible label - which implies that you didn't provide a working reproduction using Sherlock. As a result, it'll be closed in a few days unless a maintainer explicitly vouches for it or you edit your first post to include a formal reproduction (you can use the playground for that).

Note that we require Sherlock reproductions for long-lived issues (rather than standalone git repositories or similar) because we're a small team. Sherlock gives us the ability to check which bugs are still affecting the master branch at any given point, and decreases the amount of code we need to run on our own machines (thus leading to faster bug resolutions). It helps us help you! 😃

If you absolutely cannot reproduce a bug on Sherlock (for example because it's a Windows-only issue), a maintainer will have to manually add the upholded label. Thanks for helping us triaging our repository! 🌟

@yarnbot yarnbot added the stale Issues that didn't get attention label Aug 29, 2021
@merceyz merceyz added the upholded Real issues without formal reproduction label Aug 29, 2021
@yarnbot yarnbot removed the stale Issues that didn't get attention label Aug 29, 2021
@KrysKruk
Copy link

To workaround this bug I used the extensions config. In my case I couldn't bundle the estree-walker package which in the package.json contains only module, not main. module points to src/index.js so I added it to the extensions list.

    plugins: [pnpPlugin({
      extensions: ['.tsx', '.ts', '.jsx', '.mjs', '.cjs', '.js', '.css', '.json', 'src/index.js']
    })],

This is a temporary fix. I believe there will be more packages like that, so the bug is still valid.

@swandir
Copy link
Contributor

swandir commented Oct 28, 2021

Related issue and an alternative workaround #2987 (comment)

@merceyz
Copy link
Member

merceyz commented Sep 2, 2022

Native support for PnP was added to esbuild@0.15.0 so @yarnpkg/esbuild-plugin-pnp is no longer required and is getting deprecated, if you experience any issues with the PnP support in esbuild please report them upstream.

@merceyz merceyz closed this as not planned Won't fix, can't repro, duplicate, stale Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upholded Real issues without formal reproduction
Projects
None yet
Development

No branches or pull requests

5 participants