question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error while using requireContext

See original GitHub issue

Once we start to use requireContext in .storybook/config.js, running the storybook is giving me an error, I was following the exact steps mentioned in tutorial.

Screenshot 2019-06-14 at 2 51 28 PM

if I start to use const req = require.context('../src', true, /.stories.js$/);, the stuffs work fine

PFB my package.json

{
  "name": "taskbox1",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-scripts": "3.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "storybook": "start-storybook -p 9009 -s public",
    "build-storybook": "build-storybook -s public"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@storybook/addon-actions": "^5.1.7",
    "@storybook/addon-links": "^5.1.7",
    "@storybook/addon-storyshots": "^5.1.7",
    "@storybook/addons": "^5.1.7",
    "@storybook/react": "^5.1.7",
    "react-test-renderer": "^16.8.6",
    "require-context.macro": "^1.0.4"
  }
}

node version : v10.13.0 yarn version: v1.15.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
skondilozacommented, Jul 1, 2019

Hi can you please update this post because it is so annoying when you follow steps and end up with errors. After so much time I figure that problem is missing dependencies. You need to install @babel/core and babel-loader for this to work. You said in your text that we need to use babel macro, and if that should make as know that we need to install this dependencies it is very unclear. So please add this two install commands in your text for future readers.

1reaction
jsmasterathulcommented, Jun 21, 2019

current version 5.1.9 works fine. thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Difference between getContext() and requireContext() when ...
getContext() returns a nullable Context . requireContext() returns a nonnull Context , or throws an exception when one isn't available.
Read more >
Got error when using require.context · Issue #1635 - GitHub
I got an error var req = require.context(path.join(ROOT, "src/pages"), ... js$/); ^ TypeError: require.context is not a function and I am on ...
Read more >
Fragment: getContext vs requireContext | by Ivan Shafran
TLDR: use requireContext only when you are sure fragment is attached to its host(onResume, onViewCreated, etc). Android team annotated some sdk ...
Read more >
Fragment | Android Developers
Static library support version of the framework's android.app.Fragment . Used to write apps that run on platforms prior to Android 3.0. When running...
Read more >
Dan Lew on Twitter: "`requireContext()` and `context!!` are the ...
I use requireContext() because the exception and message in ... I prefer using the requireXxx methods and if I get an error, at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found