@babel/runtime should be listed as a dependency instead of babel-runtime
kengorab opened this issue · 0 comments
The Bug
When looking at the compiled code which is included at runtime (react-scrollspy@3.4.2), there are calls to import files under the @babel/runtime
package, eg.
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
This throws an error at runtime, since it's not guaranteed that the @babel/runtime
dependency is installed.
Steps to Reproduce
You can reproduce this with a super minimal example:
mkdir bug-repro && cd !$
npm init -y
npm i react react-dom react-scrollspy
node -e "require('react-scrollspy')"
The output of which will be:
node -e "require('react-scrollspy')"
internal/modules/cjs/loader.js:969
throw err;
^
Error: Cannot find module '@babel/runtime/helpers/interopRequireDefault'
Require stack:
- /Users/kengorab/code/bug-repro/node_modules/react-scrollspy/lib/scrollspy.js
- /Users/kengorab/code/bug-repro/[eval]
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/Users/kengorab/code/bug-repro/node_modules/react-scrollspy/lib/scrollspy.js:3:30)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/kengorab/code/bug-repro/node_modules/react-scrollspy/lib/scrollspy.js',
'/Users/kengorab/code/bug-repro/[eval]'
]
}
Potential Solution
A workaround for this would just be to explicitly depend on @babel/runtime
, but this package should include it in its dependencies so npm/yarn can resolve it correctly. It appears this has a dependency on babel-runtime
, which could probably just be changed to @babel/runtime
to resolve this issue.
Note this might not be an issue in newer projects which were built with create-react-app
, as react-scripts
pulls in @babel/runtime
.