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

Dynamic Requires not working #443

Closed
SachaG opened this issue Sep 14, 2016 · 6 comments
Closed

Dynamic Requires not working #443

SachaG opened this issue Sep 14, 2016 · 6 comments

Comments

@SachaG
Copy link
Contributor

SachaG commented Sep 14, 2016

I'm trying to get dynamic requires to work but I'm running into a weird issue.

The following works:

require("foo.md")

But this gives me Uncaught Error: Cannot find module '../../data/features/foo.md'.:

const path = "foo.md"
require(path)

How can I get dynamic requires to work?

@KyleAMathews
Copy link
Contributor

Does something different happen if you do:

const path = "./foo.md"
require(path)

@SachaG
Copy link
Contributor Author

SachaG commented Sep 15, 2016

Well in my case the path is actually ../../foo.md.

@KyleAMathews
Copy link
Contributor

It's a bit hard to debug this without seeing your directory structure etc. I can't think of anything that Gatsby would be doing to cause trouble with dynamic requires.

If you haven't read over this doc that might help: https://webpack.github.io/docs/context.html

Something I've found useful in the past is finding and examining the context module that's created.

@KyleAMathews
Copy link
Contributor

Also something that's tripped me up a few times is that if Webpack has trouble loading your loader then it won't tell you that. So if you've customized the markdown loader, put a console.log in there to make sure it's getting run.

@SachaG
Copy link
Contributor Author

SachaG commented Sep 15, 2016

OK, thanks for the tips. But I can work around it so I'll probably leave it for later.

@KyleAMathews
Copy link
Contributor

Ok great. I'll close this issue for now. Please reopen it if you discover it is a Gatsby caused problem.

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

No branches or pull requests

2 participants