-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Import d3 causes webpack dependency errors #2107
Comments
Probably you installed the d3-node module by accident which then webpack is choking on trying to import as it's trying to import a bunch of node only modules. |
its interesting that the error is so misleading, maybe we can fix it. e.g. if the target is not Node in webpack we shouldn't recommend installing core node modules. |
@KyleAMathews I don't think that's the case. The d3 documentation itself recommends using If you have any ideas about how to debug this issue, that'd be very helpful. |
looks like this xmlhttprequest module is not webpack friendly :/ related : driverdan/node-XMLHttpRequest#127 |
@revolunet Why is xmlhttprequest getting required by d3 in the first place? |
no idea , could be some other module |
Some findings:
Strange though because this issue seems to not appear when using a very plain |
The plain webpack was version 3. Using the It would be interesting to talk to |
Known |
Commit: d3/d3-request@d635b89#diff-b9cfc7f2cdf78a7f4b91a753d10865a2L19 Solution: Add this to the webpack config: {
resolve: {
packageMains: [
'module', // adds check for 'module'
'webpack',
'browser',
'web',
'browserify',
['jam', 'main'],
'main',
]
}
} See |
I added the packageMains, but still not working. I use Webpack1. Anyone know what to do to get rid of the XMLHttpRequest and fs error? |
yep, getting the same issue as @hermionewy when using @haroldtreen 's solution with
I was able to get it to work with this, but I'm afraid that will have unintended consequences down the line.
|
No i think that's the right way to handle this @mattjstar we should make those the defaults for v2 ( #2641) |
I'm getting a similar error with fs being required by dotenv, which I presume showed up after reinstalling my node modules a couple of days ago, but I just noticed it today:
@mattjstar's fix works for me too. EDIT: No it didn't - it stopped the error messages from appearing, but then dotenv stopped working. |
@richardwestenra is this error happening in the browser? If so, know that dotenv is only useful in node.js code so shouldn't be required in the browser. |
@KyleAMathews Nope, this error is happening in the terminal, confusingly. I've tried moving it to devDependencies, as well as setting config.merge({
target: 'node'
}); in the webpack config, but have had no success 😕 |
Webpack is only for browser code so unless you're requiring dotenv in browser code modifying the webpack config isn't going to help with node code. Confusing I know :-) |
ah okay, that helps narrow things down a bit. Does that mean it's unlikely to be a Gatsby-related issue, then? I'm pretty much stumped for ideas. I'm using dotenv to populate Contentful/Workable API keys used in plugins in gatsby-config.js, having initialised dotenv at the start of that file. |
Perhaps try But yeah, this is either an install problem or a dotenv problem. Node.js is somehow failing to require the built-in fs module. |
Have tried that several times, and it doesn't look like dotenv has published any releases in a year. I'll keep looking. Thanks for the assistance! :) |
Okay I figured it out! I'm unsure whether it's relevant to others' issues posted above, but I'll post details of my solution here in case it helps anyone. It turns out, the issue showed up when I started including Is there a recommended way of including gatsby-config's siteMetadata prop in browser code? If not, what is its purpose? |
Yes, via GraphQL. See https://www.gatsbyjs.org/tutorial/part-four/#our-first-graphql-query |
ah okay, great, thanks! I didn't spot that, but I guess it'll be included in the documentation when the GraphQL docs page is done. Thanks again for your help! |
You can also follow this approach to fix the XMLHTTPRequest issue with module bundling: |
I am seeing the same |
@haroldtreen where should i add this? If i add |
I am facing exactly the same error as @richardwestenra when installing the gatsby-plugin-mailchimp and using dotenv. Is there a way to resolve it in that case? |
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub issues, we have to clean some of the old issues as many of them have already been resolved with the latest updates. Please make sure to update to the latest Gatsby version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 |
This issue is being closed because there hasn't been any activity for at least 30 days. Feel free to open a new one if you still experience this problem 👍 |
Adding the line
import * as d3 from 'd3'
to any JS file in my src code causes the following errors:Could this be a bug caused by Gatsby's webpack config? I don't understand what's going on here: Why is XMLHttpRequest throwing an error when it tries to require built in node modules like
fs
andchild_process
, and why would these errors be triggered by includingd3
?More info
gatsby-config.js
gatsby-node.js
:package.json
:Repo and branch in which error is occuring: https://github.com/nwshane/nwshane.github.io/tree/blog
Gatsby version: 1.9.21
NodeJS version: 8.4.0
OS version: Mac OS X 10.12
The text was updated successfully, but these errors were encountered: