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

Fix importing npm packages with same name of Node built-ins #2072

Merged
merged 1 commit into from
Nov 6, 2022

Conversation

mrbbot
Copy link
Contributor

@mrbbot mrbbot commented Oct 24, 2022

Previously, if node_compat was disabled, and the user had an npm package with the same name as a Node built-in module installed (e.g. buffer), esbuild would always throw instead of resolving it. This PR fixes the issue by relying on esbuild's resolver, and instead rewriting the error message on failure to suggest enabling node_compat instead of platform: "node".

Closes #2038

@changeset-bot
Copy link

changeset-bot bot commented Oct 24, 2022

🦋 Changeset detected

Latest commit: 2750ecb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Oct 24, 2022

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/3405110305/npm-package-wrangler-2072

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/2072/npm-package-wrangler-2072

Or you can use npx with this latest build directly:

npx https://prerelease-registry.developers.workers.dev/runs/3405110305/npm-package-wrangler-2072 dev path/to/script.js
Additional artifacts:
npm install https://prerelease-registry.developers.workers.dev/runs/3405110305/npm-package-cloudflare-pages-shared-2072

@mrbbot mrbbot force-pushed the bcoll/fix-npm-node-builtin-import branch from a7ea4a7 to 1731a12 Compare October 24, 2022 10:38
Previously, if `node_compat` was disabled, and the user had an npm package with
the same name as a Node built-in module installed (e.g. `buffer`), esbuild
would always throw instead of resolving it. This PR fixes the issue by relying
on esbuild's resolver, and instead rewriting the error message on failure to
suggest enabling `node_compat` instead of `platform: "node"`.

Closes #2038
@mrbbot mrbbot force-pushed the bcoll/fix-npm-node-builtin-import branch from 1731a12 to 2750ecb Compare November 6, 2022 16:25
@codecov
Copy link

codecov bot commented Nov 6, 2022

Codecov Report

Merging #2072 (2750ecb) into main (49b6a48) will increase coverage by 0.07%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2072      +/-   ##
==========================================
+ Coverage   73.41%   73.48%   +0.07%     
==========================================
  Files         139      139              
  Lines        8965     8985      +20     
  Branches     2327     2334       +7     
==========================================
+ Hits         6582     6603      +21     
+ Misses       2383     2382       -1     
Impacted Files Coverage Δ
packages/wrangler/src/bundle.ts 85.00% <100.00%> (+0.97%) ⬆️
packages/wrangler/src/index.tsx 83.60% <100.00%> (+0.26%) ⬆️
packages/wrangler/src/logger.ts 100.00% <100.00%> (ø)
...ackages/wrangler/src/__tests__/helpers/mock-bin.ts 100.00% <0.00%> (+5.26%) ⬆️

@mrbbot mrbbot merged commit 06aa612 into main Nov 6, 2022
@mrbbot mrbbot deleted the bcoll/fix-npm-node-builtin-import branch November 6, 2022 16:38
@github-actions github-actions bot mentioned this pull request Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 BUG: Detecting a npm package as node built-in
2 participants