Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

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

Closed
hath995 opened this issue Jan 23, 2019 · 7 comments
Closed

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

hath995 opened this issue Jan 23, 2019 · 7 comments

Comments

@hath995
Copy link

hath995 commented Jan 23, 2019

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
Copy link
Author

hath995 commented Jan 23, 2019

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
Copy link
Author

hath995 commented Jan 23, 2019

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
Copy link
Author

hath995 commented Jan 23, 2019

index.ts

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

@hath995
Copy link
Author

hath995 commented Jan 23, 2019

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
Copy link

benjamind commented Feb 14, 2019

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
Copy link
Contributor

allex commented Feb 20, 2019

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

@dima-takoy-zz
Copy link

PR merged. Can we close?

@TrySound TrySound closed this as completed May 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants