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

node:path is not bundled for the browser when outputFormat is esmodule or global #8409

Closed
aminya opened this issue Aug 20, 2022 · 6 comments
Closed
Labels
🐛 Bug Stale Inactive issues

Comments

@aminya
Copy link
Contributor

aminya commented Aug 20, 2022

🐛 bug report

I am using is-path-inside in my package that uses node:path. But when I try to bundle it for the browser it fails with this error:

@parcel/packager-js: External modules are not supported when building for browser

patha/node_modules/.pnpm/is-path-inside@4.0.0/node_modules/is-path-inside/index.js:1:18
  > 1 | import path from 'node:path';
  >   |                  ^^^^^^^^^^^
    2 | 

🎛 Configuration (.babelrc, package.json, cli command)

  "main.browser": "./dist/browser/index.js",
  "source": "./src/index.ts",
  "browser": {
    "path": "./node_modules/path-browserify",
    "process": "./node_modules/process"
  },
  "targets": {
    "main.browser": {
      "context": "browser",
      "engines": {
        "browsers": "> 0.5%"
      },
      "optimize": true,
      "includeNodeModules": true,
      "outputFormat": "global",
      "isLibrary": true
    }
  },
parcel build --target main.browser

🤔 Expected Behavior

global should bundle node:path similar to esmodule or commonjs

😯 Current Behavior

💁 Possible Solution

🔦 Context

Might be related to #8049

💻 Code Sample

aminya/patha#5

🌍 Your Environment

Software Version(s)
Parcel 2.6.2
Node 16
npm/Yarn pnpm
Operating System Ubuntu 22
@aminya
Copy link
Contributor Author

aminya commented Aug 20, 2022

If the output format is esmodule, it doesn't error out, but it just copy-pastes node:path into the final bundle without doing anything about it.

@devongovett
Copy link
Member

It's due to isLibrary:

// By default, exclude node builtins from libraries unless explicitly opted in.
if (
env.isLibrary &&
this.shouldIncludeNodeModule(env, filename) !== true
) {
return null;
}

This setting is not meant to work with the global output format. You should either switch to commonjs or esmodule, or remove isLibrary.

@aminya
Copy link
Contributor Author

aminya commented Aug 23, 2022

But I want to make a library for the browser users. If I remove isLibrary then the functions are not properly exported.

You should either switch to commonjs or esmodule, or remove isLibrary.

I have switched to esmodule, but node:path is not still bundled. That's why my Deno integration test fails.

https://github.com/aminya/patha/runs/7936632445?check_suite_focus=true#step:8:41

@aminya aminya changed the title node:path is not bundled for the browser when outputFormat is global node:path is not bundled for the browser when outputFormat is esmodule or global Aug 23, 2022
@github-actions github-actions bot added the Stale Inactive issues label Feb 19, 2023
@aminya
Copy link
Contributor Author

aminya commented Feb 19, 2023

It is not fixed yet.

@github-actions github-actions bot removed the Stale Inactive issues label Feb 19, 2023
@String10
Copy link

String10 commented Aug 9, 2023

Face similar issue while bundling a project depending on axios. Parcel just writes require ("buffer") to the output even I set true to includeNodeModules in targets. Besides, I set type commonjs but nothing else in package.json.

It seems that parcel doesn't include the packages to the output file which are not just under the folder node_modules but in node cache.

Copy link

github-actions bot commented Feb 5, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

@github-actions github-actions bot added the Stale Inactive issues label Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Stale Inactive issues
Projects
None yet
Development

No branches or pull requests

4 participants