Closed hath995 closed 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?
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
});
index.ts
import io from 'socket.io-client';
io(link, {transports: ['websocket']} );
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",
}
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.
should be solve in PR #183,
or use @allex/rollup-plugin-node-resolve
instead for temporarily.
PR merged. Can we close?
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