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

Parcel Canary: Cannot bundle Nodejs ESModule with dynamic imports #9925

Open
aminya opened this issue Aug 23, 2024 · 1 comment
Open

Parcel Canary: Cannot bundle Nodejs ESModule with dynamic imports #9925

aminya opened this issue Aug 23, 2024 · 1 comment

Comments

@aminya
Copy link
Contributor

aminya commented Aug 23, 2024

🐛 bug report

If I add a esmodule target I get this error. After debugging, I realized this line in Parcel returns true. As far as I know, Nodejs supports Dynamic imports natively.

  let needsDynamicImportPolyfill = !bundle.env.isLibrary && !bundle.env.supports('dynamic-import', true);
@parcel/runtime-js: No import() polyfill available for context 'node'

  Error: No import() polyfill available for context 'node'
      at nullthrows (.../setup-cpp/node_modules/.pnpm/nullthrows@1.1.1/node_modules/nullthrows/nullthrows.js:7:15)
      at getLoaderRuntime
  (.../setup-cpp/node_modules/.pnpm/@parcel+runtime-js@2.0.0-canary.1720_@parcel+core@2.0.0-canary.1718_@swc+helpers@0.5.12_/node_modules/@parcel/runtime-js/lib/JSRuntime.js:360:42)
      at Object.apply
  (.../setup-cpp/node_modules/.pnpm/@parcel+runtime-js@2.0.0-canary.1720_@parcel+core@2.0.0-canary.1718_@swc+helpers@0.5.12_/node_modules/@parcel/runtime-js/lib/JSRuntime.js:171:29)
      at applyRuntimes
  (.../setup-cpp/node_modules/.pnpm/@parcel+core@2.0.0-canary.1718_@swc+helpers@0.5.12/node_modules/@parcel/core/lib/applyRuntimes.js:114:44)
      at async BundlerRunner.bundle
  (.../setup-cpp/node_modules/.pnpm/@parcel+core@2.0.0-canary.1718_@swc+helpers@0.5.12/node_modules/@parcel/core/lib/requests/BundleGraphRequest.js:334:25)
      at async Object.run
  (.../setup-cpp/node_modules/.pnpm/@parcel+core@2.0.0-canary.1718_@swc+helpers@0.5.12/node_modules/@parcel/core/lib/requests/BundleGraphRequest.js:132:17)
      at async RequestTracker.runRequest
  (.../setup-cpp/node_modules/.pnpm/@parcel+core@2.0.0-canary.1718_@swc+helpers@0.5.12/node_modules/@parcel/core/lib/RequestTracker.js:784:20)
      at async Object.run
  (.../setup-cpp/node_modules/.pnpm/@parcel+core@2.0.0-canary.1718_@swc+helpers@0.5.12/node_modules/@parcel/core/lib/requests/ParcelBuildRequest.js:52:7)
      at async RequestTracker.runRequest
  (.../setup-cpp/node_modules/.pnpm/@parcel+core@2.0.0-canary.1718_@swc+helpers@0.5.12/node_modules/@parcel/core/lib/RequestTracker.js:784:20)
      at async Parcel._build
  (.../setup-cpp/node_modules/.pnpm/@parcel+core@2.0.0-canary.1718_@swc+helpers@0.5.12/node_modules/@parcel/core/lib/Parcel.js:369:11)

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

The modern config fails.

https://github.com/aminya/setup-cpp/tree/modern

 "targets": {
    "main": {
      "context": "node",
      "engines": {
        "node": ">=12.x"
      },
      "includeNodeModules": true,
      "optimize": true,
      "outputFormat": "commonjs"
    },
    "actions": {
      "context": "node",
      "engines": {
        "node": ">=20.x"
      },
      "includeNodeModules": true,
      "optimize": true,
      "outputFormat": "commonjs"
    },
    "modern": {
      "context": "node",
      "engines": {
        "node": ">=22.x"
      },
      "includeNodeModules": true,
      "optimize": true,
      "outputFormat": "esmodule"
    }
  }

🤔 Expected Behavior

Not sure why isLibrary matters here in determining the dynamic import support. But it could be related.

😯 Current Behavior

💁 Possible Solution

🔦 Context

💻 Code Sample

https://github.com/aminya/setup-cpp/tree/modern
aminya/setup-cpp#265

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-canary.1718
Node 22
npm/Yarn pnpm 9.8
Operating System KDE Neon Ubuntu 22.04
@aminya
Copy link
Contributor Author

aminya commented Aug 31, 2024

The workaround for this is to specify isLibrary: true in the package.json for the target.

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

No branches or pull requests

1 participant