Closed coreyward closed 6 years ago
Thanks for the detailed write-up! That is... not a very helpful error, you're right. It looks like the actual error message isn't being shown, just the stack trace?
I think that error message is created around here. Could you do some digging and see if there's additional info that's not being reported to the terminal?
You could dive straight in to node_modules/gatsby/dist/commands/build-html.js
for the transpiled ES5 code, or follow the contributing docs to set up a local Gatsby dev environment.
Alternatively if you're able to share a public repo I can take a look?
Thanks for the guidance, @m-allanson. I was able to log the stats.toJson().errors
and there is indeed an error message that isn't getting printed to the terminal.
Unfortunately, it looks like something I previously thought I solved coming back to bite me: I can't figure out how to import CSS without a relative path during build (hence the build-javascript
changes above). Perhaps I need to apply the same changes to the build-html
stage as well? Is there a better way of handling imports in CSS (plain CSS, not Sass)?
./src/shared/components/external_page/external_page.module.css
Module build failed: ModuleNotFoundError: Module not found: Error: Cannot resolve 'file' or 'directory' ../../styles/constants/constants in /Users/corey/src/thisproject/src/shared/components/external_page
at /Users/corey/src/thisproject/node_modules/webpack/lib/Compilation.js:229:38
I'm 99% certain the file exists at the path specified, but apparently I'm not as accurate as a machine and I make typos, so here's the relevant portion of the file tree if you want to check my work:
src/
βββ pages
βΒ Β βββ 404.js
βΒ Β βββ 404.module.css
βββ shared
βΒ Β βββ components
βΒ Β βΒ Β βββ external_page
βΒ Β βΒ Β βΒ Β βββ external_page.css.d.ts
βΒ Β βΒ Β βΒ Β βββ external_page.module.css
βΒ Β βΒ Β βΒ Β βββ external_page.tsx
βΒ Β βββ styles
βΒ Β βββ constants
βΒ Β βΒ Β βββ constants.css
βββ templates
βββ text_page.jsx
Okay, so I was able to get past this by adding in this config.merge
call to the build-javascript
and build-html
/develop-html
stages of the Gatsby webpack.config.js
:
// node_modules/gatsby/dist/utils/webpack.config.js:198
// CSS modules
config.loader(`cssModules`, {
test: /\.module\.css$/,
loader: (0, _gatsby1ConfigExtractPlugin.extractTextPlugin)(stage).extract(`style`, [(0, _gatsby1ConfigCssModules.cssModulesConfig)(stage), `postcss`])
});
// These lines added
config.merge({
postcss: [require(`postcss-import`)(), require(`postcss-cssnext`)({
browsers: program.browserslist
})]
});
// End of added lines
return config;
I have a limited understanding what these lines do, but I suspect the postcss-import
is what we're missing.
Seems like issue was resolved and what caused by custom webpack modifications, so I'll close this.
Description
I'm running into an issue where
gatsby build
is failing on the secondBuilding static HTML for pages
despitegatsby develop
running. I've followed the advice in the docs regarding ensuringwindow
anddocument
aren't referenced outside ofcomponentDidMount
andcomponentWillUnmount
to no avail.The particular error message I'm getting is rather unhelpful (I reduced vertical whitespace for formatting reasons):
At a glance, I'm using the postcss out of the box and have some βlegacyβ TypeScript stuff, but most of my pages are in ES6 JS. I have a single file under
pages
(404.js) and a template undersrc/templates
that I use in conjunction withcreatePage
in my gatsby-node.js.I've gone through and commented out swaths of code that I thought might be responsible, including temporarily killing dependencies like
@vimeo/player
ordynamic_dom
(which I also tried to disable using thenull-loader
pattern I saw in these issues).I also tried looking at the
.cache/static-entry.js
file at the referenced line (172:16) but I couldn't figure out where it might be relevant. I also naively added someconsole.log
statements, but they were swiftly destroyed on the next call togatsby build
. π€¦ββοΈEnvironment
npm list gatsby
): 1.9.246gatsby --version
): 1.1.49File contents (if changed):
gatsby-config.js
:package.json
:gatsby-node.js
:This is modified per this issue and specifically this post to resolve issues I was having with relative CSS imports (non-Sass).
The other changes are to resolve this issue (called out) and to configure SVGR to be simpler to use (no url imports, which we don't use on this project).
gatsby-browser.js
: Not presentgatsby-ssr.js
: Not present