rollup / rollup-plugin-node-resolve

This module has moved and is now available at @rollup/plugin-node-resolve / https://github.com/rollup/plugins/blob/master/packages/node-resolve
MIT License
469 stars 96 forks source link

Using `modulesOnly: true` triggers unresolved dependency even when target defines module entry #200

Closed natevw closed 5 years ago

natevw commented 5 years ago

I am compiling code like this:

import { render } from 'preact';   // @10.0.0-alpha.2

Using this via --config rollup.config.mjs:

import resolve from 'rollup-plugin-node-resolve';

export default {
  plugins: [ resolve({
    browser: true,
    modulesOnly: true
  }) ]
}

Preact's package.json includes:

  "module": "dist/preact.mjs",

But I still get an error:

(!) Unresolved dependencies https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency preact (imported by myfile.mjs)

natevw commented 5 years ago

UPDATE: this doesn't work — see later comment.


Turns out this is due to https://github.com/rollup/rollup-plugin-node-resolve/issues/144#issuecomment-405210086. If I add the .mjs extension to my config, the error goes away:

import resolve from 'rollup-plugin-node-resolve';

export default {
  plugins: [ resolve({
    browser: true,
    modulesOnly: true,
    extensions: [ '.mjs', '.js']
  }) ]
}

(A preact workaround for this sort of behavior would also avoid this gotcha: https://github.com/developit/preact/pull/1425)

natevw commented 5 years ago

I spoke to soon. Not sure what I was testing, but adding .mjs as a supported extension does not fix this after all 🙁

natevw commented 5 years ago

Looks like preact is exporting multiple items, which is probably breaking isModule: https://github.com/component/is-module/issues/3

dima-takoy-zz commented 5 years ago

I tried to reproduce it with the latest versions. All works perfectly! Repro here: https://github.com/mecurc/200-rollup-issue

Used versions:

"preact": "10.0.0-beta.1",
"rollup": "^1.11.3",
"rollup-plugin-node-resolve": "^4.2.3"

Console output:

$ rollup -c

src/index.js → dist/bundle.js...
created dist/bundle.js in 278ms
Done in 0.71s

Can be closed now.