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: The plugin "native-node-modules" didn't set a resolve directory for the file #589

Closed
jlarmstrongiv opened this issue Mar 16, 2022 · 4 comments
Labels
bug Something isn't working released

Comments

@jlarmstrongiv
Copy link

jlarmstrongiv commented Mar 16, 2022

I am trying to make my own cli version of https://github.com/githubocto/repo-visualizer, and bundle it with tsup. This means bundling for node, while including react for svg rendering.

My current config includes:

{
  skipNodeModulesBundle: true,
  '--': [],
  entry: [ 'src/index.tsx', 'src/cli.tsx' ],
  inject: [ './inject-react-import.js' ],
  external: [ 'react' ],
  format: [ 'esm', 'cjs', 'iife' ],
  silent: true,
  minify: true,
  incremental: true,
  dts: true,
  sourcemap: true,
  clean: false,
  splitting: false
}

and the ./inject-react-import.js is:

import * as React from "react";

export { React };

This error was actually quite hard to find any info on. However, I believe the root cause is from https://github.com/egoist/tsup/blob/da9011f924e5b628505498cf8866b91a09208fe3/src/esbuild/native-node-module.ts

The full error message is:

✘ [ERROR] Could not resolve "/Users/jlarmst/Desktop/monorepos/turbo-monorepo/node_modules/react-dom/server.node.js"

    node-file:/Users/jlarmst/Desktop/monorepos/turbo-monorepo/node_modules/react-dom/server.node.js:2:27:
      2 │           import path from "/Users/jlarmst/Desktop/monorepos/turbo-monorepo/node_modules/react-dom/server.node.js"
        ╵                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  The plugin "native-node-modules" didn't set a resolve directory for the file
  "node-file:/Users/jlarmst/Desktop/monorepos/turbo-monorepo/node_modules/react-dom/server.node.js",
  so esbuild did not search for
  "/Users/jlarmst/Desktop/monorepos/turbo-monorepo/node_modules/react-dom/server.node.js" on the
  file system.

IIFE Build failed
Error: Build failed with 1 error:
node-file:/Users/jlarmst/Desktop/monorepos/turbo-monorepo/node_modules/react-dom/server.node.js:2:27: ERROR: Could not resolve "/Users/jlarmst/Desktop/monorepos/turbo-monorepo/node_modules/react-dom/server.node.js"
    at failureErrorWithLog (/Users/jlarmst/Desktop/monorepos/turbo-monorepo/node_modules/esbuild/lib/main.js:1605:15)
    at /Users/jlarmst/Desktop/monorepos/turbo-monorepo/node_modules/esbuild/lib/main.js:1251:28
    at runOnEndCallbacks (/Users/jlarmst/Desktop/monorepos/turbo-monorepo/node_modules/esbuild/lib/main.js:1036:63)
    at buildResponseToResult (/Users/jlarmst/Desktop/monorepos/turbo-monorepo/node_modules/esbuild/lib/main.js:1249:7)
    at /Users/jlarmst/Desktop/monorepos/turbo-monorepo/node_modules/esbuild/lib/main.js:1358:14
    at /Users/jlarmst/Desktop/monorepos/turbo-monorepo/node_modules/esbuild/lib/main.js:668:9
    at handleIncomingPacket (/Users/jlarmst/Desktop/monorepos/turbo-monorepo/node_modules/esbuild/lib/main.js:765:9)
    at Socket.readFromStdout (/Users/jlarmst/Desktop/monorepos/turbo-monorepo/node_modules/esbuild/lib/main.js:635:7)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:293:12)

My current workarounds include using:

import ReactDOMServer from "react-dom/server.js";

not

import ReactDOMServer from "react-dom/server";

and removingiife from tsupConfig.format entirely.

Also, tsup really seems to hate lodash, and only lodash-es seems to work. Makes migrating old code more difficult.

Possibly related evanw/esbuild#1051

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@jlarmstrongiv
Copy link
Author

Related #579

@yovanoc
Copy link

yovanoc commented Apr 2, 2022

related too evanw/esbuild#2148

@egoist egoist added the bug Something isn't working label Apr 2, 2022
@egoist egoist closed this as completed in e5fe1c1 Apr 2, 2022
@github-actions
Copy link

github-actions bot commented Apr 2, 2022

🎉 This issue has been resolved in version 5.12.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@jlarmstrongiv
Copy link
Author

Confirmed fix, thanks @egoist 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

No branches or pull requests

3 participants