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

node-resolve ignoring package.browser module: false #197

Closed hath995 closed 5 years ago

hath995 commented 5 years ago

I'm trying to bundle socket.io-client, however, it has a dependency engine.io-client, which uses a module named "ws" while in node and in the browser it use the native websocket object. In it's package.json in the browser section it specifies that "ws":false such that other module bundlers seem to know to leave it out.

It doesn't look like rollup-plugin-node-resolve is respecting this and is importing the module anyway causing the bundle to break in the browser. Is this a bug or is this an unimplemented feature?

https://github.com/socketio/engine.io-client/blob/master/package.json#L71

hath995 commented 5 years ago

Additionally it is also ignoring the next line "xmlhttprequest-ssl": "./lib/xmlhttprequest.js", so maybe the browser: true property is not propagated for recursively resolved modules?

hath995 commented 5 years ago

My rollup setup

const rollup = require('rollup');
const resolve = require('rollup-plugin-node-resolve');
const cjs = require('rollup-plugin-commonjs');
const typescript = require('rollup-plugin-typescript');

  const main = await rollup.rollup({
    input: './index.ts',
    plugins: [
      typescript(),
      resolve({browser: true}),
      cjs()
    ]
  })

  await main.write({
    name: "main",
    format: 'iife',
    file: './build/index.js',
    sourcemap: true
  });
hath995 commented 5 years ago

index.ts

import io from 'socket.io-client';
io(link, {transports: ['websocket']} );
hath995 commented 5 years ago

package.json

  "dependencies": {
    "rollup": "^1.1.2",
    "rollup-plugin-commonjs": "^9.2.0",
    "rollup-plugin-node-resolve": "^4.0.0",
    "rollup-plugin-typescript": "^1.0.0",
    "socket.io-client": "^2.1.1",
    "tslib": "^1.9.3",
    "typescript": "^3.2.4",
  }
benjamind commented 5 years ago

I'm also having the same problem with a package which imports uuid internally. It seems like the browser mapping is not being respected in nested dependencies. Seems like there have been a few regressions of this bug before and PR #143 seems related.

allex commented 5 years ago

should be solve in PR #183, or use @allex/rollup-plugin-node-resolve instead for temporarily.

dima-takoy-zz commented 5 years ago

PR merged. Can we close?