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

[Bug]: Failed to resolve entry for package "fs" #23557

Closed
jeniabrook opened this issue Jul 21, 2023 · 3 comments
Closed

[Bug]: Failed to resolve entry for package "fs" #23557

jeniabrook opened this issue Jul 21, 2023 · 3 comments

Comments

@jeniabrook
Copy link

Describe the bug

I have a monorepo with yarn 1.22.19 and managed by turborepo.

I suddenly started to get the Failed to resolve entry for package "fs" error in dev and when I try to build the storybook (also the same error when building on Vercel).

I've tried removing node_modules and yarn.lock, and install it clean, didn't help.

To Reproduce

I tried to reproduce it on StackBlitz with no luck.

System

Environment Info:
  System:
    OS: macOS 13.4.1
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.16.0/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
  Browsers:
    Chrome: 114.0.5735.198
    Safari: 16.5.1

Additional context

On dev, this is the trace that I have:

yarn workspace design-system dev
yarn workspace v1.22.19
yarn run v1.22.19
$ storybook dev -p 6006
@storybook/cli v7.1.0

info => Serving static files from ././fonts at /assets/fonts
info => Starting manager..
╭────────────────────────────────────────────────────╮
│                                                    │
│   Storybook 7.1.0 for react-vite started           │
│   118 ms for manager and 909 ms for preview        │
│                                                    │
│    Local:            http://localhost:6006/        │
│    On your network:  http://10.100.102.10:6006/    │
│                                                    │
╰────────────────────────────────────────────────────╯
✘ [ERROR] Could not resolve "@emotion/react"

    ../../node_modules/@emotion/styled/dist/emotion-styled.browser.esm.js:5:7:
      5 │ import '@emotion/react';
        ╵        ~~~~~~~~~~~~~~~~

  You can mark the path "@emotion/react" as external to exclude it from the bundle, which will
  remove this error.

✘ [ERROR] Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json. [plugin vite:dep-pre-bundle]

    ../../node_modules/vite/node_modules/esbuild/lib/main.js:1370:21:
      1370 │         let result = await callback({
           ╵                      ^

    at packageEntryFailure (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28698:11)
    at resolvePackageEntry (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28695:5)
    at tryNodeResolve (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28429:20)
    at Context.resolveId (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28190:28)
    at Object.resolveId (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:44130:64)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:65730:21
    at async file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:39879:34
    at async requestCallbacks.on-resolve (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:1370:22)
    at async handleRequest (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:729:13)

  This error came from the "onResolve" callback registered here:

    ../../node_modules/vite/node_modules/esbuild/lib/main.js:1289:20:
      1289 │       let promise = setup({
           ╵                     ^

    at setup (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:39859:19)
    at handlePlugins (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:1289:21)
    at buildOrContextImpl (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:978:5)
    at Object.buildOrContext (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:786:5)
    at /Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:2182:68
    at new Promise (<anonymous>)
    at Object.context (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:2182:27)
    at Object.context (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:2022:58)
    at prepareEsbuildOptimizerRun (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:45883:35)

  The plugin "vite:dep-pre-bundle" was triggered by this import

    ../../node_modules/graceful-fs/graceful-fs.js:1:17:
      1 │ var fs = require('fs')
        ╵                  ~~~~

✘ [ERROR] Could not resolve "@emotion/react"

    ../../node_modules/@emotion/styled/base/dist/emotion-styled-base.browser.esm.js:4:47:
      4 │ import { withEmotionCache, ThemeContext } from '@emotion/react';
        ╵                                                ~~~~~~~~~~~~~~~~

  You can mark the path "@emotion/react" as external to exclude it from the bundle, which will
  remove this error.

/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:1646
  let error = new Error(`${text}${summary}`);
              ^

Error: Build failed with 3 errors:
../../node_modules/@emotion/styled/base/dist/emotion-styled-base.browser.esm.js:4:47: ERROR: Could not resolve "@emotion/react"
../../node_modules/@emotion/styled/dist/emotion-styled.browser.esm.js:5:7: ERROR: Could not resolve "@emotion/react"
../../node_modules/vite/node_modules/esbuild/lib/main.js:1370:21: ERROR: [plugin: vite:dep-pre-bundle] Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json.
    at failureErrorWithLog (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:1646:15)
    at /Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:1058:25
    at /Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:1522:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errors: [
    {
      detail: undefined,
      id: '',
      location: {
        column: 47,
        file: '../../node_modules/@emotion/styled/base/dist/emotion-styled-base.browser.esm.js',
        length: 16,
        line: 4,
        lineText: "import { withEmotionCache, ThemeContext } from '@emotion/react';",
        namespace: '',
        suggestion: ''
      },
      notes: [
        {
          location: null,
          text: 'You can mark the path "@emotion/react" as external to exclude it from the bundle, which will remove this error.'
        }
      ],
      pluginName: '',
      text: 'Could not resolve "@emotion/react"'
    },
    {
      detail: undefined,
      id: '',
      location: {
        column: 7,
        file: '../../node_modules/@emotion/styled/dist/emotion-styled.browser.esm.js',
        length: 16,
        line: 5,
        lineText: "import '@emotion/react';",
        namespace: '',
        suggestion: ''
      },
      notes: [
        {
          location: null,
          text: 'You can mark the path "@emotion/react" as external to exclude it from the bundle, which will remove this error.'
        }
      ],
      pluginName: '',
      text: 'Could not resolve "@emotion/react"'
    },
    {
      detail: Error: Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json.
          at packageEntryFailure (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28698:11)
          at resolvePackageEntry (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28695:5)
          at tryNodeResolve (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28429:20)
          at Context.resolveId (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28190:28)
          at Object.resolveId (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:44130:64)
          at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
          at async file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:65730:21
          at async file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:39879:34
          at async requestCallbacks.on-resolve (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:1370:22)
          at async handleRequest (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:729:13),
      id: '',
      location: {
        column: 21,
        file: '../../node_modules/vite/node_modules/esbuild/lib/main.js',
        length: 0,
        line: 1370,
        lineText: '        let result = await callback({\n' +
          '    at packageEntryFailure (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28698:11)\n' +
          '    at resolvePackageEntry (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28695:5)\n' +
          '    at tryNodeResolve (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28429:20)\n' +
          '    at Context.resolveId (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28190:28)\n' +
          '    at Object.resolveId (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:44130:64)\n' +
          '    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
          '    at async file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:65730:21\n' +
          '    at async file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:39879:34\n' +
          '    at async requestCallbacks.on-resolve (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:1370:22)\n' +
          '    at async handleRequest (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:729:13)',
        namespace: 'file',
        suggestion: ''
      },
      notes: [
        {
          location: {
            column: 20,
            file: '../../node_modules/vite/node_modules/esbuild/lib/main.js',
            length: 0,
            line: 1289,
            lineText: '      let promise = setup({\n' +
              '    at setup (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:39859:19)\n' +
              '    at handlePlugins (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:1289:21)\n' +
              '    at buildOrContextImpl (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:978:5)\n' +
              '    at Object.buildOrContext (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:786:5)\n' +
              '    at /Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:2182:68\n' +
              '    at new Promise (<anonymous>)\n' +
              '    at Object.context (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:2182:27)\n' +
              '    at Object.context (/Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/esbuild/lib/main.js:2022:58)\n' +
              '    at prepareEsbuildOptimizerRun (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:45883:35)',
            namespace: 'file',
            suggestion: ''
          },
          text: 'This error came from the "onResolve" callback registered here:'
        },
        {
          location: {
            column: 17,
            file: '../../node_modules/graceful-fs/graceful-fs.js',
            length: 4,
            line: 1,
            lineText: "var fs = require('fs')",
            namespace: '',
            suggestion: ''
          },
          text: 'The plugin "vite:dep-pre-bundle" was triggered by this import'
        }
      ],
      pluginName: 'vite:dep-pre-bundle',
      text: 'Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json.'
    }
  ],
  warnings: []
}

Node.js v18.16.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1
Command: /Users/jeniabrook/.nvm/versions/node/v18.16.0/bin/node
Arguments: /Users/jeniabrook/.cache/node/corepack/yarn/1.22.19/lib/cli.js dev
Directory: /Users/jeniabrook/projects/miranda/apps/design-system
Output:

info Visit https://yarnpkg.com/en/docs/cli/workspace for documentation about this command.

On build, this is the trace that I have:

yarn workspace design-system build
yarn workspace v1.22.19
yarn run v1.22.19
$ storybook build
@storybook/cli v7.1.0

info => Cleaning outputDir: /storybook-static
info => Loading presets
info => Building manager..
info => Manager built (96 ms)
info => Copying static files: /Users/jeniabrook/projects/miranda/node_modules/@storybook/manager/static at /Users/jeniabrook/projects/miranda/apps/design-system/storybook-static/sb-common-assets
vite v4.4.4 building for production...

./sb-common-assets/fonts.css doesn't exist at build time, it will remain unchanged to be resolved at runtime
transforming (26) ../../node_modules/@storybook/addon-links/dist/chunk-JT3VIYBO.mjsinfo => Copying static files: /Users/jeniabrook/projects/miranda/apps/design-system/fonts at /Users/jeniabrook/projects/miranda/apps/design-system/storybook-static/assets/fonts
[plugin:vite:resolve] Module "path" has been externalized for browser compatibility, imported by "/Users/jeniabrook/projects/miranda/node_modules/jest-mock/node_modules/jest-util/build/requireOrImportModule.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "url" has been externalized for browser compatibility, imported by "/Users/jeniabrook/projects/miranda/node_modules/jest-mock/node_modules/jest-util/build/requireOrImportModule.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
✓ 125 modules transformed.
✓ built in 886ms
[commonjs--resolver] Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json.
file: /Users/jeniabrook/projects/miranda/node_modules/jest-mock/build/index.js
ERR! Error: Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json.
ERR!     at packageEntryFailure (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28698:11)
ERR!     at resolvePackageEntry (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28695:5)
ERR!     at tryNodeResolve (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28429:20)
ERR!     at Object.resolveId (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28190:28)
ERR!     at file:///Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:25332:40
ERR!     at async PluginDriver.hookFirstAndGetPlugin (file:///Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:25232:28)
ERR!     at async resolveId (file:///Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:23907:26)
ERR!     at async ModuleLoader.resolveId (file:///Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:24321:15)
ERR!     at async file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:8187:16
ERR!     at async Promise.all (index 0)
ERR!     at async file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:8179:32
ERR!     at async rewriteRequireExpressionsAndGetImportBlock (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:8755:28)
ERR!     at async transformCommonjs (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:9318:23)
ERR!     at async transform (file:///Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:24239:16)
ERR!     at async ModuleLoader.addModuleSource (file:///Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:24439:30)
ERR!  Error: Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json.
ERR!     at packageEntryFailure (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28698:11)
ERR!     at resolvePackageEntry (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28695:5)
ERR!     at tryNodeResolve (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28429:20)
ERR!     at Object.resolveId (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:28190:28)
ERR!     at file:///Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:25332:40
ERR!     at async PluginDriver.hookFirstAndGetPlugin (file:///Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:25232:28)
ERR!     at async resolveId (file:///Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:23907:26)
ERR!     at async ModuleLoader.resolveId (file:///Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:24321:15)
ERR!     at async file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:8187:16
ERR!     at async Promise.all (index 0)
ERR!     at async file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:8179:32
ERR!     at async rewriteRequireExpressionsAndGetImportBlock (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:8755:28)
ERR!     at async transformCommonjs (file:///Users/jeniabrook/projects/miranda/node_modules/vite/dist/node/chunks/dep-abb4f102.js:9318:23)
ERR!     at async transform (file:///Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:24239:16)
ERR!     at async ModuleLoader.addModuleSource (file:///Users/jeniabrook/projects/miranda/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:24439:30) {
ERR!   code: 'PLUGIN_ERROR',
ERR!   plugin: 'commonjs--resolver',
ERR!   hook: 'resolveId',
ERR!   id: '/Users/jeniabrook/projects/miranda/node_modules/jest-mock/build/index.js',
ERR!   watchFiles: [
ERR!     '/Users/jeniabrook/projects/miranda/apps/design-system/iframe.html',
ERR!     '/virtual:/@storybook/builder-vite/vite-app.js',
ERR!     '\x00vite/modulepreload-polyfill',
ERR!     '/virtual:/@storybook/builder-vite/setup-addons.js',
ERR!     '/virtual:/@storybook/builder-vite/storybook-stories.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/react/dist/config.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-links/dist/preview.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-essentials/dist/docs/preview.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-essentials/dist/actions/preview.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-essentials/dist/backgrounds/preview.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-essentials/dist/measure/preview.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-essentials/dist/outline/preview.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-essentials/dist/highlight/preview.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-interactions/dist/preview.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/apps/design-system/node_modules/@storybook/addon-styling/dist/preview.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/apps/design-system/.storybook/preview.ts',
ERR!     '\x00vite/preload-helper',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/prop-types/index.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/html-tags/index.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/escodegen/escodegen.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/ts-dedent/esm/index.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/react/node_modules/acorn-jsx/index.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/lodash/isPlainObject.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/lodash/isFunction.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/lodash/isString.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/react-element-to-jsx-string/dist/esm/index.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/react/index.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/react/dist/chunk-JWY6Y6NU.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/docs-tools/dist/index.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/react/node_modules/acorn/dist/acorn.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/react/node_modules/acorn-walk/dist/walk.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-actions/dist/preview.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-links/dist/chunk-VJY7NXNQ.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-links/dist/chunk-DXNAW7Q2.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-links/dist/chunk-JT3VIYBO.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-measure/dist/preview.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-outline/dist/preview.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-backgrounds/dist/preview.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/jest-mock/build/index.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-interactions/dist/chunk-NNAAFZ4U.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/global/dist/index.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/instrumenter/dist/index.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-highlight/dist/preview.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-docs/dist/preview.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/apps/design-system/package.json',
ERR!     '/Users/jeniabrook/projects/miranda/apps/design-system/index.css',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-viewport/dist/index.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/prop-types/factoryWithThrowingShims.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/lodash/_baseGetTag.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/lodash/_getPrototype.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/lodash/isObjectLike.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/lodash/isObject.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/lodash/isArray.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/react/node_modules/acorn-jsx/xhtml.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/estraverse/estraverse.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/esutils/lib/utils.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/source-map/source-map.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/escodegen/package.json',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@base2/pretty-print-object/dist/index.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/react-element-to-jsx-string/node_modules/react-is/index.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/is-plain-object/dist/is-plain-object.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/html-tags/html-tags.json',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/lodash/mapValues.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/doctrine/lib/doctrine.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/react/cjs/react.production.min.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/react-dom-shim/dist/react-18.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-actions/dist/chunk-AY7I2SME.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-actions/dist/chunk-VWCVBQ22.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/csf/dist/index.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/tiny-invariant/dist/esm/tiny-invariant.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-measure/dist/chunk-YIXVQKZ5.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-highlight/dist/chunk-33ALZPRS.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-outline/dist/chunk-2DMOCDBJ.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-backgrounds/dist/chunk-GRJZJKJ4.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-docs/dist/DocsRenderer-3PUGWF3O.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/jest-mock/node_modules/jest-util/build/index.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/lodash/_overArg.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/lodash/_Symbol.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/lodash/_getRawTag.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/lodash/_objectToString.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-viewport/dist/chunk-32QKCLIG.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/@storybook/addon-viewport/dist/chunk-BLYPNILM.mjs',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/prop-types/lib/ReactPropTypesSecret.js',
ERR!     '/Users/jeniabrook/projects/miranda/packages/ui/src/components/Text/Text.stories.tsx',
ERR!     '/Users/jeniabrook/projects/miranda/packages/ui/src/components/Heading/Heading.stories.tsx',
ERR!     '\x00commonjsHelpers.js',
ERR!     '\x00/Users/jeniabrook/projects/miranda/node_modules/@storybook/react/node_modules/acorn-jsx/index.js?commonjs-module',
ERR!     '\x00/Users/jeniabrook/projects/miranda/node_modules/@storybook/react/node_modules/acorn-jsx/xhtml.js?commonjs-proxy',
ERR!     '\x00/Users/jeniabrook/projects/miranda/node_modules/@storybook/react/node_modules/acorn/dist/acorn.mjs?commonjs-proxy',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/esutils/lib/ast.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/esutils/lib/code.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/esutils/lib/keyword.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/source-map/lib/source-map-generator.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/source-map/lib/source-map-consumer.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/source-map/lib/source-node.js',
ERR!     '\x00/Users/jeniabrook/projects/miranda/node_modules/@base2/pretty-print-object/dist/index.js?commonjs-exports',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/lodash/_baseAssignValue.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/lodash/_baseForOwn.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/lodash/_baseIteratee.js',
ERR!     '/Users/jeniabrook/projects/miranda/node_modules/doctrine/lib/typed.js',
ERR!     ... 105 more items
ERR!   ]
ERR! }
[plugin:vite:resolve] Module "constants" has been externalized for browser compatibility, imported by "/Users/jeniabrook/projects/miranda/node_modules/graceful-fs/polyfills.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "stream" has been externalized for browser compatibility, imported by "/Users/jeniabrook/projects/miranda/node_modules/graceful-fs/legacy-streams.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "path" has been externalized for browser compatibility, imported by "/Users/jeniabrook/projects/miranda/node_modules/picomatch/lib/picomatch.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "path" has been externalized for browser compatibility, imported by "/Users/jeniabrook/projects/miranda/node_modules/picomatch/lib/utils.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "path" has been externalized for browser compatibility, imported by "/Users/jeniabrook/projects/miranda/node_modules/picomatch/lib/constants.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
✖ Would you like to help improve Storybook by sending anonymous crash reports? … yes
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1
Command: /Users/jeniabrook/.nvm/versions/node/v18.16.0/bin/node
Arguments: /Users/jeniabrook/.cache/node/corepack/yarn/1.22.19/lib/cli.js build
Directory: /Users/jeniabrook/projects/miranda/apps/design-system
Output:

info Visit https://yarnpkg.com/en/docs/cli/workspace for documentation about this command.

package.json:

{
  "name": "design-system",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "dev": "storybook dev -p 6006",
    "build": "storybook build",
    "lint": "eslint ."
  },
  "dependencies": {
    "@flare/ui": "*"
  },
  "devDependencies": {
    "@flare/eslint-config": "*",
    "@storybook/addon-essentials": "^7.1.0",
    "@storybook/addon-interactions": "^7.1.0",
    "@storybook/addon-links": "^7.1.0",
    "@storybook/addon-styling": "^1.3.4",
    "@storybook/blocks": "^7.1.0",
    "@storybook/react": "^7.1.0",
    "@storybook/react-vite": "^7.1.0",
    "@storybook/testing-library": "^0.2.0",
    "@vitejs/plugin-react": "^4.0.3",
    "autoprefixer": "^10.4.14",
    "postcss": "^8.4.26",
    "storybook": "^7.1.0",
    "tailwindcss": "^3.3.3",
    "vite": "^4.4.4"
  }
}
@jeniabrook
Copy link
Author

I've found the problem.
I've added a new app to the monorepo, since yarn is hoisting the packages, somehow it conflicted with other dependencies.

The current solution is to add a "nohoist" under workspaces in root package.json file.

@phthhieu
Copy link

For anyone who found this thread, in our project we fix this problem by:

  • Using nohoist as Jeniabrook's comment (but the cons is it will affect others packages as well)
  • Or replacing fs by a node polyfill such as memfs in the vite config
{
    resolve: {
      alias: [
        {
          find: 'fs',
          replacement: 'memfs',
        },
      ],
    },
}

@evanheisler
Copy link

I had a similar problem but ended up solving it a little different. In my Turborepo, I have a Storybook app that is an Expo/RN app. When running natively, I would run into issues from the source-map package attempting to use fs and path. Under normal circumstances (e.g. not a monorepo) the runtime env is determined correctly and module resolution isn't a problem.

I'm also using NPM Workspaces so hoisting wasn't an option. I added this to my metro.config.js with stubs for those Node libs (since this is only an SB app):

config.resolver.extraNodeModules = {
  fs: path.resolve(projectRoot, 'mocks/fs.js'),
  path: path.resolve(projectRoot, 'mocks/path.js'),
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

3 participants