I upgraded my project to v2 and everything builds fine locally and I'm able to run gatsby develop successfully. However in TeamCity when trying to build for CI/production environments, gatsby fails when trying to generate the javascript bundles with an error: Error: ./.cache/production-app.js Module not found: Error: Can't resolve 'gatsby-react-router-scroll' in 'C:\BuildAgent\work\391d5c6454c1827f\.cache'
I've verified that node_modules/gatsby-react-router-scroll is installed locally when I run gatsby build.
Unless you have TeamCity I'm not sure what I can tell you here, sorry 😞
The build completes successfully as it did when it ran locally.
TeamCity reported an error:
[23:02:50][npm run build] success open and validate gatsby-config — 0.009 s
[23:02:50][npm run build] success load plugins — 0.246 s
[23:02:50][npm run build] success onPreInit — 0.310 s
[23:02:50][npm run build] success delete html and css files from previous builds — 0.007 s
[23:02:50][npm run build] success initialize cache — 0.010 s
[23:02:50][npm run build] success copy gatsby files — 0.097 s
[23:02:50][npm run build] success onPreBootstrap — 0.001 s
[23:02:51][npm run build] success source and transform nodes — 0.760 s
[23:02:52][npm run build] success building schema — 1.188 s
[23:02:55][npm run build] success createPages — 2.895 s
[23:02:55][npm run build] success createPagesStatefully — 0.011 s
[23:02:55][npm run build] success onPreExtractQueries — 0.000 s
[23:02:57][npm run build] success update schema — 1.681 s
[23:02:57][npm run build] success extract queries from components — 0.188 s
[23:03:00][npm run build] success run graphql queries — 2.334 s — 1131/1131 485.01 queries/second
[23:03:00][npm run build] success write out page data — 0.022 s
[23:03:00][npm run build] success write out redirect data — 0.001 s
[23:03:00][npm run build] success onPostBootstrap — 0.003 s
[23:03:00][npm run build]
[23:03:00][npm run build] info bootstrap finished - 14.728 s
[23:03:00][npm run build]
[23:03:21][npm run build] error Generating JavaScript bundles failed
Error: ./.cache/production-app.js
[23:03:21][npm run build] Module not found: Error: Can't resolve 'gatsby-react-router-scroll' in 'C:\Bui ldAgent\work\391d5c6454c1827f\.cache'
[23:03:21][npm run build] resolve 'gatsby-react-router-scroll' in 'C:\BuildAgent\work\391d5c6454c1827f\. cache'
[23:03:21][npm run build] Parsed request is a module
[23:03:21][npm run build] using description file: C:\BuildAgent\work\391d5c6454c1827f\package.json (re lative path: ./.cache)
[23:03:21][npm run build] Field 'browser' doesn't contain a valid alias configuration
[23:03:21][npm run build] resolve as module
[23:03:21][npm run build] looking for modules in C:\\BuildAgent\\work\\391d5c6454c1827f\\src\\node _modules
[23:03:21][npm run build] using description file: C:\BuildAgent\work\391d5c6454c1827f\package.js on (relative path: ./src//node_modules)
[23:03:21][npm run build] Field 'browser' doesn't contain a valid alias configuration
[23:03:21][npm run build] using description file: C:\BuildAgent\work\391d5c6454c1827f\package. json (relative path: ./src/node_modules/gatsby-react-router-scroll)
[23:03:21][npm run build] no extension
[23:03:21][npm run build] Field 'browser' doesn't contain a valid alias configuration
[23:03:21][npm run build] C:\BuildAgent\work\391d5c6454c1827f\src\node_modules\gatsby-reac t-router-scroll doesn't exist
[23:03:21][npm run build] .js
[23:03:21][npm run build] Field 'browser' doesn't contain a valid alias configuration
[23:03:21][npm run build] C:\BuildAgent\work\391d5c6454c1827f\src\node_modules\gatsby-reac t-router-scroll.js doesn't exist
[23:03:21][npm run build] .jsx
[23:03:21][npm run build] Field 'browser' doesn't contain a valid alias configuration
[23:03:21][npm run build] C:\BuildAgent\work\391d5c6454c1827f\src\node_modules\gatsby-reac t-router-scroll.jsx doesn't exist
[23:03:21][npm run build] as directory
[23:03:21][npm run build] C:\BuildAgent\work\391d5c6454c1827f\src\node_modules\gatsby-reac t-router-scroll doesn't exist
[23:03:21][npm run build] C:\BuildAgent\work\391d5c6454c1827f\.cache\node_modules doesn't exist or is not a directory
[23:03:21][npm run build] C:\BuildAgent\work\node_modules doesn't exist or is not a directory
[23:03:21][npm run build] C:\BuildAgent\node_modules doesn't exist or is not a directory
[23:03:21][npm run build] C:\node_modules doesn't exist or is not a directory
[23:03:21][npm run build] looking for modules in C:\BuildAgent\work\391d5c6454c1827f\node_modules
[23:03:21][npm run build] using description file: C:\BuildAgent\work\391d5c6454c1827f\package.js on (relative path: ./node_modules)
[23:03:21][npm run build] Field 'browser' doesn't contain a valid alias configuration
[23:03:21][npm run build] using description file: C:\BuildAgent\work\391d5c6454c1827f\package. json (relative path: ./node_modules/gatsby-react-router-scroll)
[23:03:21][npm run build] no extension
[23:03:21][npm run build] Field 'browser' doesn't contain a valid alias configuration
[23:03:21][npm run build] C:\BuildAgent\work\391d5c6454c1827f\node_modules\gatsby-react-ro uter-scroll doesn't exist
[23:03:21][npm run build] .js
[23:03:21][npm run build] Field 'browser' doesn't contain a valid alias configuration
[23:03:21][npm run build] C:\BuildAgent\work\391d5c6454c1827f\node_modules\gatsby-react-ro uter-scroll.js doesn't exist
[23:03:21][npm run build] .jsx
[23:03:21][npm run build] Field 'browser' doesn't contain a valid alias configuration
[23:03:21][npm run build] C:\BuildAgent\work\391d5c6454c1827f\node_modules\gatsby-react-ro uter-scroll.jsx doesn't exist
[23:03:21][npm run build] as directory
[23:03:21][npm run build] C:\BuildAgent\work\391d5c6454c1827f\node_modules\gatsby-react-ro uter-scroll doesn't exist
[23:03:21][npm run build] [C:\BuildAgent\work\391d5c6454c1827f\src\node_modules\gatsby-react-router-scro ll]
[23:03:21][npm run build] [C:\BuildAgent\work\391d5c6454c1827f\src\node_modules\gatsby-react-router-scro ll.js]
[23:03:21][npm run build] [C:\BuildAgent\work\391d5c6454c1827f\src\node_modules\gatsby-react-router-scro ll.jsx]
[23:03:21][npm run build] [C:\BuildAgent\work\391d5c6454c1827f\.cache\node_modules]
[23:03:21][npm run build] [C:\BuildAgent\work\node_modules]
[23:03:21][npm run build] [C:\BuildAgent\node_modules]
[23:03:21][npm run build] [C:\node_modules]
[23:03:21][npm run build] [C:\BuildAgent\work\391d5c6454c1827f\node_modules\gatsby-react-router-scroll]
[23:03:21][npm run build] [C:\BuildAgent\work\391d5c6454c1827f\node_modules\gatsby-react-router-scroll.j s]
[23:03:21][npm run build] [C:\BuildAgent\work\391d5c6454c1827f\node_modules\gatsby-react-router-scroll.j sx]
[23:03:21][npm run build] @ ./.cache/production-app.js 10:0-59 70:33-46
System:
OS: Windows 10
CPU: x64 Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz
Binaries:
Yarn: 1.7.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.1.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 42.17134.1.0
npmPackages:
gatsby: 2.0.0-beta.93 => 2.0.0-beta.93
gatsby-module-loader: 2.0.0-alpha.3 => 2.0.0-alpha.3
gatsby-plugin-google-tagmanager: 2.0.0-beta.3 => 2.0.0-beta.3
gatsby-plugin-react-helmet: 2.0.11 => 2.0.11
gatsby-plugin-sass: 2.0.0-beta.6 => 2.0.0-beta.6
gatsby-source-aem: 1.8.8 => 1.8.8
gatsby-source-filesystem: 2.0.1-beta.10 => 2.0.1-beta.10
gatsby-source-wordpress: 2.0.93 => 2.0.93
gatsby-transformer-json: 2.1.1-beta.4 => 2.1.1-beta.4
gatsby-config.js:
module.exports = {
pathPrefix: 'path/prefix',
plugins: [
'gatsby-plugin-sass',
'gatsby-plugin-react-helmet',
'gatsby-transformer-json',
// gtm plugin, filesystem plugins
package.json:
"scripts": {
// other scripts ...
// This is what gets run on TeamCity
"build": "npm run test && npm run teamcity-lint && gatsby build --prefix-paths",
// other scripts ...
}
gatsby-node.js: N/A
gatsby-browser.js:
const getPolyfills = () => {
if (!('IntersectionObserver' in window)) {
require('intersection-observer');
}
};
exports.onClientEntry = () => {
getPolyfills();
};
gatsby-ssr.js: N/A
Can you try deleting your lock file and node_modules and reinstalling? Sounds like your dependencies didn't get upgraded correctly.
Yeeeeah I did a fresh install and then realized we weren't committing our lock file. Adding it to the repository fixed the build 😅 Thanks for getting back to me so quickly, sorry for the dumb issue!
Most helpful comment
Can you try deleting your lock file and node_modules and reinstalling? Sounds like your dependencies didn't get upgraded correctly.