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

TypeError: The "id" argument must be of type string. Received an instance of Object #18801

Closed
asasvirtuais opened this issue Jul 27, 2022 · 19 comments
Assignees

Comments

@asasvirtuais
Copy link

After running storybook-start or build-sb I get the following

The error doesn't stop the execution and after a few seconds I get to use storybook or build it. Unfortunately this might relate to Chromatic which I am trying to use.

chromaui/chromatic-cli#618

ERR! TypeError: The "id" argument must be of type string. Received an instance of Object
ERR!     at new NodeError (node:internal/errors:371:5)
ERR!     at validateString (node:internal/validators:119:11)
ERR!     at Module.require (node:internal/modules/cjs/loader:998:3)    
ERR!     at require (node:internal/modules/cjs/helpers:102:18)
ERR!     at interopRequireDefault (C:\Users\icaro\Desktop\code\gsg\gsg-workspace\node_modules\.pnpm\@storybook+core-common@6.5.9_6mntlpnkhn6c7tucibhqtuw2yq\node_modules\@storybook\core-common\dist\cjs\presets.js:178:16)
ERR!     at getContent (C:\Users\icaro\Desktop\code\gsg\gsg-workspace\node_modules\.pnpm\@storybook+core-common@6.5.9_6mntlpnkhn6c7tucibhqtuw2yq\node_modules\@storybook\core-common\dist\cjs\presets.js:194:10)     
ERR!     at loadPreset (C:\Users\icaro\Desktop\code\gsg\gsg-workspace\node_modules\.pnpm\@storybook+core-common@6.5.9_6mntlpnkhn6c7tucibhqtuw2yq\node_modules\@storybook\core-common\dist\cjs\presets.js:203:20)     
ERR!     at C:\Users\icaro\Desktop\code\gsg\gsg-workspace\node_modules\.pnpm\@storybook+core-common@6.5.9_6mntlpnkhn6c7tucibhqtuw2yq\node_modules\@storybook\core-common\dist\cjs\presets.js:256:18
ERR!     at Array.reduce (<anonymous>)
ERR!     at loadPresets (C:\Users\icaro\Desktop\code\gsg\gsg-workspace\node_modules\.pnpm\@storybook+core-common@6.5.9_6mntlpnkhn6c7tucibhqtuw2yq\node_modules\@storybook\core-common\dist\cjs\presets.js:255:18)    
ERR!  TypeError: The "id" argument must be of type string. Received an 
instance of Object
ERR!     at new NodeError (node:internal/errors:371:5)
ERR!     at validateString (node:internal/validators:119:11)
ERR!     at Module.require (node:internal/modules/cjs/loader:998:3)    
ERR!     at require (node:internal/modules/cjs/helpers:102:18)
ERR!     at interopRequireDefault (C:\Users\icaro\Desktop\code\gsg\gsg-workspace\node_modules\.pnpm\@storybook+core-common@6.5.9_6mntlpnkhn6c7tucibhqtuw2yq\node_modules\@storybook\core-common\dist\cjs\presets.js:178:16)
ERR!     at getContent (C:\Users\icaro\Desktop\code\gsg\gsg-workspace\node_modules\.pnpm\@storybook+core-common@6.5.9_6mntlpnkhn6c7tucibhqtuw2yq\node_modules\@storybook\core-common\dist\cjs\presets.js:194:10)     
ERR!     at loadPreset (C:\Users\icaro\Desktop\code\gsg\gsg-workspace\node_modules\.pnpm\@storybook+core-common@6.5.9_6mntlpnkhn6c7tucibhqtuw2yq\node_modules\@storybook\core-common\dist\cjs\presets.js:203:20)     
ERR!     at C:\Users\icaro\Desktop\code\gsg\gsg-workspace\node_modules\.pnpm\@storybook+core-common@6.5.9_6mntlpnkhn6c7tucibhqtuw2yq\node_modules\@storybook\core-common\dist\cjs\presets.js:256:18
ERR!     at Array.reduce (<anonymous>)
ERR!     at loadPresets (C:\Users\icaro\Desktop\code\gsg\gsg-workspace\node_modules\.pnpm\@storybook+core-common@6.5.9_6mntlpnkhn6c7tucibhqtuw2yq\node_modules\@storybook\core-common\dist\cjs\presets.js:255:18) {  
ERR!   code: 'ERR_INVALID_ARG_TYPE'
ERR! }
@asasvirtuais
Copy link
Author

asasvirtuais commented Jul 27, 2022

I added the following to debug and workaround the issue.

@storybook\core-common\dist\cjs\presets.js:178

function interopRequireDefault(filePath) {
  // Log was giving me { type: "presets", name: undefined }
  console.log(filePath)
  // So I skipped that one
  if ( filePath.type === 'presets' && undefined === filePath.name ) {
    return {}
  }
  // eslint-disable-next-line global-require,import/no-dynamic-require
  var result = require(filePath);

  var isES6DefaultExported = typeof result === 'object' && result !== null && typeof result.default !== 'undefined';
  return isES6DefaultExported ? result.default : result;
}

This also fixed my issue with chromatic chromaui/chromatic-cli#618

@lukesiedle
Copy link

Had the same issue (using vite), but turned out to be an addon defined in .storybook/main.js that I had actually removed from dependencies. Removing the addon from here solved the issue.

module.exports = {
  ...,
  addons: [ ] 
}

@ColmBhandal
Copy link

ColmBhandal commented Aug 9, 2022

Given @lukesiedle's discovery, it would be helpful if running Storybook failed with a more informative error in the case where an addon is used and that addon does not exist as a dependency in the project. E.g. something like:

WARNING: Addon X is defined in ...path/main.js/module.exports but does not exist as a dependency in this project. The addon will be skipped.

I believe the fix could be implemented in presets.ts, int the function resolveAddonName. At the end of that function, it happily resolves a non-existent addon to the object:

    return {
      type: 'presets',
      name: undefined
    };

Since the name comes back as undefined, it doesn't get output in JSON.stringify when the error is logged downstream in the function loadPreset:

catch (e: any) {
    const warning =
      level > 0
        ? `  Failed to load preset: ${JSON.stringify(input)} on level ${level}`
        : `  Failed to load preset: ${JSON.stringify(input)}`;

    logger.warn(warning);
    logger.error(e);

    return [];
  }

For me, this results in this warning in my console:

info => Loading presets
WARN   Failed to load preset: {"type":"presets"} on level 1

A failure further upstream in resolveAddonName would have access to the original name it was trying to resolve and could print a more informative error/warning to the log.

@rosskevin
Copy link

Agreed, as I was migrating our addon to 7.0.0-alpha.18, I forgot to change (inside the addon project)

- addons: ["../preset.js", "@storybook/addon-essentials"],
+ addons: ["../manager.js", "@storybook/addon-essentials"],

So this error bubbled up. A more informative message would indeed be helpful.

iRuxu added a commit to deepberry/titan-web-components that referenced this issue Aug 10, 2022
@sophher
Copy link

sophher commented Aug 11, 2022

Changing

- addons: ['@storybook/addon-links/preset'],
+ addons: ['@storybook/addon-links'],

fixed it for me

@robespmun
Copy link

Changing

- addons: ['@storybook/addon-links/preset'],
+ addons: ['@storybook/addon-links'],

fixed it for me

Fixed it for me too! Thanks for the tip

@janaagaard75
Copy link

We had this issue because addons: ["@storybook-react-i18next"] should have been written addons: ["storybook-react-i18next"]. The misconfiguration wasn't reported with Storybook 6.5.9, but it became apparent with version 6.5.12.

@BibhushanKarki
Copy link

I'm using storybook v6.5.12. I'm getting this same error. How to fix this?

@EricDeColS
Copy link

EricDeColS commented Oct 19, 2022

It just started happening to me, it broke down earlier, I made it work again, wento to work, came back to my personal project without touching a finger on it, and now it's just broken

Edit: Hey, if you are using react above 17, webpack 5 compatibility and so on, get rid of '@storybook-addon-designs' if you have it, just solved my problem.

@bryanhidalgo
Copy link

bryanhidalgo commented Oct 26, 2022

I had the same issue with @storybook/preset-create-react-app, I removed it and that fixed it.

@hyeongrok7874
Copy link

I had the same issue with @storybook/preset-create-react-app, I removed it and that fixed it.

Thanks I solved it 😍

@robksawyer
Copy link

I removed @whitespace/storybook-addon-html and it worked for me.

@LordZombi
Copy link

Error message is really confusing.
Point is to have installed (listed in your package.json) all the addons you are using in storybook.
So I think proper fix is just update an error message.

@Jero786
Copy link

Jero786 commented Dec 23, 2022

I needed to remove both add-ons in order to avoid that error

"@storybook/preset-create-react-app",
"@storybook/addon-a11y"

@IanVS IanVS self-assigned this Dec 30, 2022
@shilman
Copy link
Member

shilman commented Jan 13, 2023

Zoinks!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.0-beta.26 containing PR #20455 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb@next upgrade --prerelease

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed Jan 13, 2023
@kevzettler
Copy link

kevzettler commented Jan 31, 2023

I am getting this issue only when I use yarns plug n play mode. If I install dependencies to node_modules I get this error

I have tried following @shilman suggestion and try upgrading with
npx sb@next upgrade --prerelease

However the upgrade process then fails at the babel migration step with error:

✅ ran autodocsTrue migration
⚠️  failed to check fix missing-babelrc
node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@babel/plugin-proposal-class-properties' imported from /Users/kevzettler/code/react-regl/babel-virtual-resolve-base.js
    at new NodeError (/Users/kevzettler/.npm/_npx/eebb2d3a7d26a7f1/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:2240:5)
    at packageResolve (/Users/kevzettler/.npm/_npx/eebb2d3a7d26a7f1/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:2776:9)
    at moduleResolve (/Users/kevzettler/.npm/_npx/eebb2d3a7d26a7f1/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:2804:18)
    at defaultResolve (/Users/kevzettler/.npm/_npx/eebb2d3a7d26a7f1/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:2835:13)
    at /Users/kevzettler/.npm/_npx/eebb2d3a7d26a7f1/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:2855:14
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/kevzettler/.npm/_npx/eebb2d3a7d26a7f1/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:45:103)
    at _next (/Users/kevzettler/.npm/_npx/eebb2d3a7d26a7f1/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:46:194)
    at /Users/kevzettler/.npm/_npx/eebb2d3a7d26a7f1/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:46:364
    at new Promise (<anonymous>) {
  code: 'ERR_MODULE_NOT_FOUND'
}

furthermore, if I revert and then use execute npx sb@next upgrade --prerelease while using yarns nodeLinker :node-modules mode. It passes successfully.

This leads me to believe in mycase there is a module resolution issue possibly with the .babelrc storybook is processing

kevzettler added a commit to kevzettler/react-regl that referenced this issue Jan 31, 2023
There is some issue with story book being unable to build in yarn plug
n play mode seems related to babel dependecy resolution storybookjs/storybook#18801 (comment)
@IanVS
Copy link
Member

IanVS commented Jan 31, 2023

@kevzettler would you mind opening a new issue with a reproduction that we can take a look into?

@kevzettler
Copy link

@IanVS I have opened a bug at: #20861

@Rutulpatel7077
Copy link

@shilman Looks like npx sb@next upgrade --prerelease fixes issues with Yarn PnP

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

No branches or pull requests