-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
TensorFlow.js cannot be bundled because it imports a module seedrandom
which is actually a CommonJS module
#4003
Comments
This shows how I could "fix" the problem with rollup plugins: jameshfisher/tfjs-seedrandom-es-module-bug#1 But it's too gross for me to accept as a solution. I think I'll have to stick with plain |
@jameshfisher I saw on the issue you filed that David said he'd be willing to accept pull requests for this on the seedrandom side, so if you do end up making a PR there let us know and we can upgrade to an es friendly release! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 dyas if no further activity occurs. Thank you. |
Closing as stale. Please @mention us if this needs more attention. |
I had this issue on some system importing tfjs from a webworker. It was easy to fix: |
7 npm resolves all dependency correctly |
System information:
2.4.0
Describe the current behavior: ES module bundler complains when bundling TensorFlow.js, because it imports a module
seedrandom
which is actually a CommonJS module.Describe the expected behavior: Running TensorFlow.js through an ES module bundler should not generate errors.
Standalone code to reproduce the issue: https://github.com/jameshfisher/tfjs-seedrandom-es-module-bug
Context: I want to use TensorFlow.js in the browser. I'm using rollup to bundle my app for the browser.
The TensorFlow.js source imports from
seedrandom
in several places. This comes through in the ES modules distributed via npm.To find the module
seedrandom
imported by TensorFlow, I'm using the plugin@rollup/plugin-node-resolve
. This does find thenode_modules/seedrandom
package.Unfortunately,
@rollup/plugin-node-resolve
does not find an ECMAScript module in the seedrandom package. So instead, it decides to bundle the seedrandomindex.js
. But this is a CommonJS module, not an ES module.As a result, rollup gives me errors like
alea is not exported by node_modules/seedrandom/index.js
, and the browser gives me errors likerequire is not defined
.I think the right solution is for the seedrandom package to provide an ES module. I noted this here. The alternative is for TensorFlow to stop importing from a package that doesn't provide an ES module.
(You might say "well you just need to use a CommonJS->ES transpiler, like @rollup/plugin-commonjs". I'm reluctant to do so, because this transformation is gross, and in general, impossible.)
The text was updated successfully, but these errors were encountered: