Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from Jun 17, 2023

Conversation

ndelangen
Copy link
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
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
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
56 checks passed
@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
@@ -24,13 +24,11 @@
".": {
"types": "./dist/index.d.ts",
"node": "./dist/index.js",
"require": "./dist/index.js",
"import": "./dist/index.mjs"
"require": "./dist/index.js"
Copy link

@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

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 patch:yes Bugfix & documentation PR that need to be picked to main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants