-
Notifications
You must be signed in to change notification settings - Fork 1
Resolve Storybook build error #98
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
Closed
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Coverage report for
|
St.❔ |
Category | Percentage | Covered / Total |
---|---|---|---|
🟢 | Statements | 97.92% | 47/48 |
🟢 | Branches | 85.71% | 6/7 |
🟢 | Functions | 100% | 8/8 |
🟢 | Lines | 100% | 40/40 |
Test suite run success
5 tests passing in 3 suites.
Report generated by 🧪jest coverage report action from 1b79c6e
This reverts commit 7b5a6db.
… Storybook build errors
lorenyu
reviewed
Apr 11, 2025
@mqwebster-nava this looks great, now that this is tested, can you copy over the changes to https://github.com/navapbc/template-application-nextjs , create a PR, tag me for review, and we can merge it from there? |
@lorenyu will do! |
mqwebster-nava
added a commit
to navapbc/template-application-nextjs
that referenced
this pull request
Apr 14, 2025
## Ticket Resolves #387 ## Changes <!-- What was added, updated, or removed in this PR. --> - Updated .storybook/main.js => .storybook/main.mjs based on ECMAScript Modules instead of CommonJS - **.storybook/main.mjs:** ``` path.resolve(import.meta.dirname, "../next.config.js") ``` ## Context for reviewers <!-- Testing instructions, background context, more in-depth details of the implementation, and anything else you'd like to call out or ask reviewers. --> Originally made an update to Storybook in #388 meant to address #387. Making these changes caused issues in [platform-test-nextjs](https://github.com/navapbc/platform-test-nextjs/actions/runs/13999633004/job/39317883628). The steps taken to resolve are in this [PR](navapbc/platform-test-nextjs#98). ## Testing <!-- Provide evidence that the code works as expected. Explain what was done for testing and the results of the test plan. Include screenshots, [GIF demos](https://getkap.co/), shell commands or output to help show the changes working as expected. ProTip: you can drag and drop or paste images into this textbox. --> Making this change in platform-test-nextjs resulted in a successful app build (save for a vulnerability scan). This change also follows [Node.js documentation](https://nodejs.org/docs/latest/api/esm.html#no-__filename-or-__dirname) on what they recommend to use in place of `__dirname`.
Resolved in navapbc/template-application-nextjs#392 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ticket
Resolves Deploy Storybook Actions step
Changes
.storybook/main.js
=>.storybook/main.mjs
based on ECMAScript Modules instead of CommonJS.storybook/main.mjs
:Context for reviewers
Storybook was having issues with building and running in the
template-application-nextjs
repo. The particular error was about.storybook/main.js
having problems with resolving the__dirname
path in the nextConfigPath variable. This issue comes from some changes in how Storybook and Node.js handle JavaScript files/modules. Storybook is having issues with using CommonJS, so the apparent solution at the time was to update the.storybook/main.js
config file to support Node.js ESM. More can be found here: template-application-next.js: issue #387.After pushing this change to main in that repo, it has caused some issues in the deployment pipeline of this one. The CI/CD pipeline failed at the Deploy Storybook step. Based on the error, the exact cause is a bit unclear because it gives the error
ReferenceError: require is not defined
which is a little confusing because.storybook/main.js
does not use this node module. It appears that this issue may be bubbling up from thenext.config.js
file as this is the only file referenced in.storybook/main.js
and it does use therequire
module. Thenext.config.js
will need to be updated to support ESM instead of CommonJS Node modules.--- Update ---
I believe I may have been over-engineering the solution to this problem. Rather than making changes to the
.storybook/main.js
ANDnext.config.js
file, I made changes to the.storybook/main.js
file only. I removed the changes I originally made in favor of usingimport.meta.dirname
in place of__dirname
based on Node.js docs. I also changed the file type from .js to .mjs to ensure this file is strictly using ESModules instead of CommonJS. This appears to resolve all build steps instead of the app vulnerability check.Testing
I've gotten this to a point where the CI/CD pipeline actions are able to run successfully except for the vulnerability check. Storybook and the rest of the app is successfully able to build after making this change to
.storybook/main.js
.Preview environment for app
♻️ Environment destroyed ♻️