storybook: Ember: Uncaught TypeError: _global.window.require is not a function

After running the storybook server, the following error pops up in the browser console:

Uncaught TypeError: _global.window.require is not a function

Originates from this line.

To Reproduce Steps to reproduce the behavior:

  1. ember new storybook-test --yarn
  2. cd storybook-test
  3. npx -p @storybook/cli sb init
  4. yarn build && yarn storybook

System:

  • OS: Ubuntu 16.04 LTS
  • Browser: Chrome, Firefox
  • Framework: Ember (3.5)
  • Version: 4.0.12
  • Node: 10.14.1
  • Yarn: 1.12.3

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 26 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I ran into this same issue. I ran the exact steps listed in the original issue.

I resolved it by doing the following:

  1. ember install @storybook/ember-cli-storybook
  2. Replacing the generated scripts in package.json with
"build-storybook": "ember build && build-storybook -s dist",
 "storybook": "ember serve & start-storybook -p 9001 -s dist"
  1. Run npm run build-storybook && npm run storybook

I keep running into this issues.

I have tried to do the following in succession:

  1. ember install @storybook/ember-cli-storybook
  2. ember build
  3. build-storybook -s dist
  4. ember serve in one terminal
  5. start-storybook -p 9003 -s dist in another

But I keep running into: _global.window.require is not a function

The file .storybook/preview-head.html is there.

It seems that the step missing from the guide is to manually install ember-cli-storybook. The guides say

Your environment will be preconfigured using ember-cli-storybook.

But I don’t think there’s anything that’s actually installing that addon when running npm i --save-dev @storybook/ember. This addon is what’s responsible for creating the .storybook/preview-head.html file which is crucial to running Stoybook.

After manually installing that addon with ember install ember-cli-storybook, my Ember app is successfully running Storybook.

Edit: It also seems that if you run the storybook script first, which does ember serve & start-storybook -p 9001 -s dist, the storybook files are not generated. You must first run the build-storybook command, which does ember build && build-storybook -p 9001 -s dist. After you do that, running the storybook command will update the files, but it seems like it doesn’t create the files initially.

here is clean repository with this issue https://github.com/killabeat/storybook-issue-4957

Possibly, or in the auto-generated scripts. The most possible cause for this problem is, when storybook is started before ember is started. That said, there are other reasons this error is showing up, such as wrong wiring of dist files that sb is not picking up.

I think, there are two use-cases:

  1. Consume storybook: run one command to spin up storybook; both (ember and sb) processes run in the same terminal
  2. Develop with storybook: Run the two commands separately, you can later decide which one you possibly want to restart, without affecting the other - so far this has become working well for me, dunno about others.

If this is the decision, we can drive this forward.

Still having this issue. Anyone find a resolution?

@gabrielcsapo Yes I tried and I encountered this error #4672.