question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bundling for Node.js fails with @rollup/plugin-node-resolve>=11.0.0

See original GitHub issue

Describe the bug

Your source code checks for something like this: typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto); to find out whether crypto is available.

I’m not sure exactly where it goes wrong, but this package inside a compiled js file with rollup, will never import crypto and only check the globals like mentioned above.

How to reproduce

With rollup and the following rollup.config, compile a file that uses “uuid”:

import typescript from "@rollup/plugin-typescript";
import commonjs from "@rollup/plugin-commonjs";
import nodeResolve from "@rollup/plugin-node-resolve";
import json from "@rollup/plugin-json";

export default {
  input: ["myfile.ts"],
  output: {
    dir: "dist",
    format: "cjs",
  },
  plugins: [
    commonjs(),
    nodeResolve(),
    json(),
    typescript(),
  ],
};

myfile.ts

import { v4 as uuidv4 } from "uuid";
console.log(uuidv4());

Expected behavior

The example should have something like const crypto = require("crypto") somewhere in the compiled code. Currently, it only checks whether it is available globally, but in my use case I’m not in a browser environment, but a nodejs environment, so it would need to get imported to work.

As a note: I can see from the source that rng.js seems to be set-up correctly, but rng-browser.js is doing the unsupported check in a node environment. So the question really is, why I’m getting the browser package instead of the node one. Can I control this? (rollup is already set-up for node, aka cjs)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

26reactions
lukastaegertcommented, Dec 8, 2020

You need to specify nodeResolve({exportConditions: ["node"]}) as node is not one of the default conditions, see the documentation: https://github.com/rollup/plugins/tree/master/packages/node-resolve#exportconditions

1reaction
ctavancommented, Dec 8, 2020

Keeping this open until https://github.com/rollup/plugins/issues/695 has settled.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js v17.0.0 - Error starting project in development mode ...
node no longer supports md4 as hash function. sha1 might be a good choice for hashing with bundles. 1
Read more >
Webpack build failing with ERR_OSSL_EVP_UNSUPPORTED
I was able to fix it via: export NODE_OPTIONS=--openssl-legacy-provider. sachaw's comment to Node.js v17.0.0 - Error starting project in ...
Read more >
Errors | Node.js v19.3.0 Documentation
AssertionError s are a special class of error that can be triggered when Node.js detects an exceptional logic violation that should never occur....
Read more >
Command-line API | Node.js v19.3.0 Documentation
If the string is not an absolute path, it's resolved as a relative path from the current working directory. That path is then...
Read more >
Deprecated APIs | Node.js v19.3.0 Documentation
Recover from failed I/O actions explicitly via error event handlers set on the domain instead. ... DEP0084: requiring bundled internal dependencies#.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found