Closed antstanley closed 6 years ago
Try to specify own extension set in nodeResolve options
Ok. So looking at the code for rollup-plugin-node-resolve
that I have in my repo from the package on npm does not match the code that is currently in master. Potentially an issue with npm publishing?
Ok. double checked. Cloned the master branch of the repo and ran npm install
it generated two files in /dist
, namely rollup-plugin-node-resolve.es.js
and rollup-plugin-node-resolve.cjs.js
When I run npm install --save-dev rollup-plugin-node-resolve
and check node_modules/rollup-plugin-node-resolve/dist
and compare the files they are different, with the installed files not having any of the .mjs
updates. Double checking package.json
it shows the latest version is installed "rollup-plugin-node-resolve": "^3.3.0"
Am running npm 6.1.0
& node 10.6.0
Closing this, as this has actually been fixed, but the the branch with .mjs support hasn't been published to npm.
Created a new more accurate issue detailing the actual problem (not published to npm) at #169
Cross-post of issue from #2333. Realised it's more likely a
rollup-plugin-node-resolve
issue than a rollup core issue.Hi!
I've got an issue bundling files where the package has .js (cjs) and .mjs (esm) versions. In my case I'm bundling Apollo GraphQL server for use in a FaaS platform.
My code imports
apollo-server-core
(cjs only) which has a peer dependency ofgraphql
(cjs and esm co-exist). It picks up thatgraphql
has esm modules and uses the root index.mjs file for that module, but sub esm modules that the root tries to import it reverts back to trying to use the .js version not the .mjs version when bundling.Error message below
Rollup Config
My app dependencies are...
I am using the
@rc
versions of these packagesMy rollup versions and plugins are...
I've created a simpler repo to reproduce the error here https://github.com/antstanley/rollup-mjs
npm install && rollup -c
should reproduce the errorI've found two workarounds.
Edit
node_modules/graphql/index.mjs
and explicitly call the .mjs version by adding `/index.mjs' to every module exported.Or add
package.json
to every sub-directory with.js
and.mjs
files exporting different module and main packages. egManually editing imported modules is not exactly ideal and not really sustainable.
Would it be possible to change the default import behaviour during bundling of Rollup to assume the same file extension as the file doing the import, unless overriden by
package.json
. So if it's bundling a.mjs
file, it expects imported modules to also be.mjs
files, unless package.json says otherwise. Or just put an order of preference, so it looks for .mjs before .js?tbh I am surprised I got this far with Rollup bundling an esm module imported from a cjs module imported by my code whilst using non-stable versions of the app modules.
This isn't urgent on my part, as this is an experiment I'm doing. Adding this issue, as I'm sure it will crop up again in the future where there are mixed
.js
and.mjs
files.