Skip to content

Core: Prebundle node-logger and make it CJS only#23109

Merged
ndelangen merged 4 commits into
nextfrom
norbert/fix-prebundle-node-logger
Jun 17, 2023
Merged

Core: Prebundle node-logger and make it CJS only#23109
ndelangen merged 4 commits into
nextfrom
norbert/fix-prebundle-node-logger

Conversation

@ndelangen
Copy link
Copy Markdown
Member

@ndelangen ndelangen commented Jun 16, 2023

I was alerted about this stack trace by @integrayshaun :

var stringWidth = require('string-width')
                  ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/shaun/Development/Integrations/storybook-clippy/node_modules/string-width/index.js from /Users/shaun/Development/Integrations/storybook-clippy/node_modules/wide-align/align.js not supported.
Instead change the require of index.js in /Users/shaun/Development/Integrations/storybook-clippy/node_modules/wide-align/align.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/shaun/Development/Integrations/storybook-clippy/node_modules/wide-align/align.js:2:19)
    at Object.<anonymous> (/Users/shaun/Development/Integrations/storybook-clippy/node_modules/gauge/render-template.js:2:13)
    at Object.<anonymous> (/Users/shaun/Development/Integrations/storybook-clippy/node_modules/gauge/plumbing.js:3:22)
    at Object.<anonymous> (/Users/shaun/Development/Integrations/storybook-clippy/node_modules/gauge/index.js:2:16)
    at Object.<anonymous> (/Users/shaun/Development/Integrations/storybook-clippy/node_modules/npmlog/log.js:3:13)
    at Object.<anonymous> (/Users/shaun/Development/Integrations/storybook-clippy/node_modules/@storybook/node-logger/dist/index.js:1:1141)
    at Object.<anonymous> (/Users/shaun/Development/Integrations/storybook-clippy/node_modules/@storybook/cli/dist/generate.js:11:4254)
    at Object.<anonymous> (/Users/shaun/Development/Integrations/storybook-clippy/node_modules/@storybook/cli/bin/index.js:9:1)
    at Object.<anonymous> (/Users/shaun/Development/Integrations/storybook-clippy/node_modules/storybook/index.js:3:1) {
  code: 'ERR_REQUIRE_ESM'

We traced it to wide-align/align.js indeed calling require('string-width'), which is not allowed by JS law.

I prebundled node-logger, meaning all dependencies are now bundled in.

@ndelangen ndelangen self-assigned this Jun 16, 2023
@ndelangen ndelangen added the bug label Jun 16, 2023
@ndelangen ndelangen added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Jun 16, 2023
@ndelangen ndelangen changed the title Ecosystem: Prebundle node-logger and make it CJS only, treeshake CJS Ecosystem: Prebundle node-logger and make it CJS only Jun 16, 2023
Copy link
Copy Markdown
Contributor

@ShaunEvening ShaunEvening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay to me 👍

@ndelangen
Copy link
Copy Markdown
Member Author

In my experiment to change the bundle script for CJS dist, the NX remote cache was corrupted somehow.
I tried a bunch of things to get it to regenerate, but it seems touching package.json is likely the best way. sigh!

@ndelangen ndelangen force-pushed the norbert/fix-prebundle-node-logger branch from a3fc22f to 8cde3f3 Compare June 16, 2023 21:36
@ndelangen ndelangen requested a review from JReinhold June 16, 2023 21:48
@ndelangen ndelangen merged commit 93d7993 into next Jun 17, 2023
@ndelangen ndelangen deleted the norbert/fix-prebundle-node-logger branch June 17, 2023 13:13
@shilman shilman changed the title Ecosystem: Prebundle node-logger and make it CJS only Core: Prebundle node-logger and make it CJS only Jun 22, 2023
@github-actions github-actions Bot mentioned this pull request Jun 22, 2023
18 tasks
@shilman shilman added the patch:done Patch/release PRs already cherry-picked to main/release branch label Jun 27, 2023
"node": "./dist/index.js",
"require": "./dist/index.js",
"import": "./dist/index.mjs"
"require": "./dist/index.js"
Copy link
Copy Markdown

@tjfred35 tjfred35 Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a setup (nx / vite) where I need the "import" declaration -- in this case, adding back "import": "./dist/index.js" would solve my issue while still using a "prebundled" version of node-logger?

This broke our upgrade from storybook 7.0.24 to 7.4.46

@ndelangen ndelangen removed the patch:yes Bugfix & documentation PR that need to be picked to main branch label Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug patch:done Patch/release PRs already cherry-picked to main/release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants