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

Most nx cli commands fail when @nx/storybook attempts parse storybook's main.ts #23228

Closed
2 of 4 tasks
RyanClementsHax opened this issue May 8, 2024 · 6 comments · Fixed by #27862
Closed
2 of 4 tasks
Assignees
Labels
outdated scope: storybook Issues related to Storybook support in Nx type: bug

Comments

@RyanClementsHax
Copy link

Current Behavior

Most nx commands fail

Expected Behavior

Nx commands can be run

GitHub Repo

https://github.com/RyanClementsHax/nx-storybook-repro

Steps to Reproduce

  1. npm install
  2. npx nx serve web-client --verbose

Nx Report

NX   Failed to process project graph.

Pass --verbose to see the stacktraces.

Failure Logs

NX   Failed to process project graph. See errors below.

Failed to process project graph.
  The "@nx/storybook/plugin" plugin threw an error while creating nodes from apps/web-client/.storybook/main.ts:
    ReferenceError: exports is not defined in ES module scope
        at file:///home/ryanclementshax/dev/mantis-todo/apps/web-client/.storybook/main.ts?t=1715126768269:2:23
        at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
        at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
        at async importModuleDynamicallyWrapper (node:internal/vm/module:431:15)
        at async load (/home/ryanclementshax/dev/mantis-todo/node_modules/@nx/devkit/src/utils/config-utils.js:82:20)
        at async loadConfigFile (/home/ryanclementshax/dev/mantis-todo/node_modules/@nx/devkit/src/utils/config-utils.js:21:30)
        at async getStorybookFramework (/home/ryanclementshax/dev/mantis-todo/node_modules/@nx/storybook/src/plugins/plugin.js:167:27)
        at async buildStorybookTargets (/home/ryanclementshax/dev/mantis-todo/node_modules/@nx/storybook/src/plugins/plugin.js:68:32)
        at async Array.exports.createNodes (/home/ryanclementshax/dev/mantis-todo/node_modules/@nx/storybook/src/plugins/plugin.js:52:15)
        at async /home/ryanclementshax/dev/mantis-todo/node_modules/nx/src/project-graph/plugins/utils.js:49:27

Package Manager Version

10.5.1

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

I'm on WSL Ubuntu 20.04

Node: v20.11.0

I was able to track down that the specific version that breaks this is 18.3.4. Given the error message, I imagine it is related to #22953

@RyanClementsHax RyanClementsHax changed the title Nx cli when trying to parse storybook's main.ts Most nx cli commands fail when @nx/storybook attempts parse storybook's main.ts May 8, 2024
@Coly010 Coly010 added the scope: storybook Issues related to Storybook support in Nx label May 9, 2024
@Coly010
Copy link
Contributor

Coly010 commented May 10, 2024

This is going to require more thought. Trying to get ts-node to actually transpile to ESM seems to have some kind of issue.

@RyanClementsHax
Copy link
Author

Thanks for your help :)

@falldowngoboone
Copy link

Is there any known workaround other than removing the plugin or reverting the version?

@njsokol
Copy link

njsokol commented Jun 7, 2024

Getting the same issue moving from 18.3.3 to 19.2.1. Seems like the issue is still persisting

@Coly010
Copy link
Contributor

Coly010 commented Sep 11, 2024

Credit to @jaysoo who figured this out. I've tested the fix out on the repro repo provided, and it works :) @RyanClementsHax once this is merged, expect it to be released either this week or next

jaysoo added a commit that referenced this issue Sep 12, 2024
…ESM (#27862)

When we load `.ts` files and the closest `package.json` specifies
`"type": "module"`, then the file may error upon loading. This happens
because we're not setting `compilerOptions` correctly when registering
`ts-node/esm`-- in fact there is no way to pass options through this
hook.

This PR sets defaults on `TS_NODE_COMPILER_OPTIONS` such that the
`module` and `moduleResolution` are correct values for ESM. It also
works for CJS since both `module` and `moduleResolution` check the
closest `package.json` to determine the format.

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #23228
FrozenPandaz pushed a commit that referenced this issue Sep 18, 2024
…ESM (#27862)

When we load `.ts` files and the closest `package.json` specifies
`"type": "module"`, then the file may error upon loading. This happens
because we're not setting `compilerOptions` correctly when registering
`ts-node/esm`-- in fact there is no way to pass options through this
hook.

This PR sets defaults on `TS_NODE_COMPILER_OPTIONS` such that the
`module` and `moduleResolution` are correct values for ESM. It also
works for CJS since both `module` and `moduleResolution` check the
closest `package.json` to determine the format.

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #23228

(cherry picked from commit 7232b39)
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: storybook Issues related to Storybook support in Nx type: bug
Projects
None yet
4 participants