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.

Netlify fails to resolve alias and build fails

See original GitHub issue

The command gatsby build fails in the Netlify CI. This might be related to the plugin gatsby-plugin-resolve-src (which exists in the package.json devDependencies and dependencies):

package.json:

{
  "name": "gatsby-starter-default",
  "description": "Gatsby default starter",
  "version": "1.0.0",
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
  "dependencies": {
    "gatsby": "^1.9.102",
    "gatsby-link": "^1.6.24",
    "gatsby-plugin-react-helmet": "^1.0.8",
    "gatsby-plugin-resolve-src": "^1.0.0"
  },
  "keywords": [
    "gatsby"
  ],
  "license": "MIT",
  "main": "n/a",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --trailing-comma es5 --no-semi --single-quote --write \"src/**/*.js\"",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "devDependencies": {
    "animejs": "^2.2.0",
    "prettier": "^1.8.1",
    "gatsby-plugin-resolve-src": "^1.0.0"
  }
}

The command gatsby build works fine in MacOS and also gatsby serve. It can be related to case sensitive imports, which I reviewed and doesn’t seem to be the case, tias.

The components are named by the directory and not file, as in:

import Foobar from 'sharedComponents/Foobar'

src
src/sharedComponents
src/sharedComponents/Foobar
src/sharedComponents/Foobar/index.js

Assuming the following algorithm ( https://nodejs.org/api/modules.html#modules_all_together )

The .nvmrc is set to:

v8.4.0

The Netlify CI error log:

10:35:35 PM: Build ready to start
10:35:36 PM: Fetching cached dependencies
10:35:36 PM: Expected build cache - but failed to find it
10:35:36 PM: Failed to extract cache, continuing with build
10:35:36 PM: No cached dependencies found. Cloning fresh repo
10:35:36 PM: git clone git@github.com:foobar/foobar-rium-ui
10:35:37 PM: git remote rm origin
10:35:37 PM: Preparing Git Reference refs/heads/master
10:35:39 PM: Running build command: gatsby build
10:35:40 PM: Using node version 'v8.4.0' from .nvmrc
10:35:41 PM: Downloading and installing node v8.4.0...
10:35:41 PM: Downloading https://nodejs.org/dist/v8.4.0/node-v8.4.0-linux-x64.tar.xz...
10:35:42 PM: 
10:35:42 PM:   0.0%
10:35:42 PM: 
10:35:42 PM:   0.9%
10:35:42 PM: 
##                                                                         3.8%
10:35:42 PM: 
##
10:35:42 PM: ###
10:35:42 PM: 
10:35:42 PM: 
10:35:42 PM: 
10:35:42 PM: 
10:35:42 PM: 
10:35:43 PM: 
10:35:43 PM: 
10:35:43 PM: 
10:35:43 PM: 
10:35:43 PM: 
10:35:43 PM: 
10:35:43 PM:                                                      7.6%
10:35:43 PM: 
##########                                                                13.9%
10:35:43 PM: 
############                                                              17.7%
10:35:43 PM: 
################                                                          22.9%
10:35:43 PM: 
##################                                                        26.3%
10:35:43 PM: 
####################                                                      29.0%
10:35:43 PM: 
####
10:35:43 PM: ####
10:35:44 PM: ##
10:35:44 PM: ##
10:35:44 PM: ##
10:35:44 PM: #
10:35:44 PM: #
10:35:44 PM: ######
10:35:44 PM:  31.6%
10:35:44 PM: 
#########################                                                 36.0%
10:35:44 PM: 
#############################                                             40.8%
10:35:44 PM: 
###############################                                           43.3%
10:35:44 PM: 
#################################                                         47.0%
10:35:44 PM: 
####################################
10:35:44 PM:    51.3%
10:35:44 PM: 
#####################################                                     52.3%
10:35:44 PM: 
#######################################                                   54.3%
10:35:45 PM: 
#########################################                                 57.4%
10:35:45 PM: 
###########################################                               60.6%
10:35:45 PM: 
##############################################                            64.8%
10:35:45 PM: 
################################################                          67.8%
10:35:45 PM: 
####################################################                      72.9%
10:35:45 PM: 
########################################################                  79.0%
10:35:45 PM: 
##########################################################                81.3%
10:35:45 PM: 
##############################################################
10:35:45 PM:  86.9%
10:35:45 PM: 
#################################################################         90.7%
10:35:45 PM: 
####################################################################      94.5%
10:35:45 PM: 
######################################################################    97.9%
10:35:45 PM: 
######################################################################## 100.0%
10:35:45 PM: Computing checksum with sha256sum
10:35:46 PM: Checksums matched!
10:35:52 PM: Now using node v8.4.0 (npm v5.3.0)
10:35:52 PM: Using version v8.4.0 of node
10:35:53 PM: Using /opt/buildhome/.rvm/gems/ruby-2.1.2
10:35:53 PM: Installing NPM modules using NPM version 5.3.0
10:35:55 PM: npm WARN
10:35:55 PM:  deprecated babel-preset-es2015@6.24.1: 🙌  Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!
10:36:32 PM: 
> uws@0.14.5 install /opt/build/repo/node_modules/uws
> node-gyp rebuild > build_log.txt 2>&1 || exit 0
10:36:50 PM: npm notice created a lockfile as package-lock.json. You should commit this file.
10:36:50 PM: npm
10:36:50 PM: WARN
10:36:50 PM:  gatsby-starter-default@1.0.0 No repository field.
10:36:50 PM: npm WARN
10:36:50 PM:  optional
10:36:50 PM:  SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/fsevents):
10:36:50 PM: npm WARN
10:36:50 PM: 
10:36:51 PM: notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
10:36:51 PM: added 1435 packages in 55.256s
10:36:51 PM: NPM modules installed
10:36:52 PM: success delete html files from previous builds — 0.051 s
10:36:52 PM: success open and validate gatsby-config.js — 0.005 s
10:36:52 PM: success copy gatsby files — 0.022 s
10:36:53 PM: success onPreBootstrap — 0.007 s
10:36:53 PM: success source and transform nodes — 0.020 s
10:36:53 PM: success building schema — 0.102 s
10:36:53 PM: success createLayouts — 0.027 s
10:36:53 PM: success createPages — 0.002 s
10:36:53 PM: success createPagesStatefully — 0.012 s
10:36:53 PM: success onPreExtractQueries — 0.001 s
10:36:53 PM: success update schema — 0.069 s
10:36:53 PM: success extract queries from components — 0.017 s
10:36:53 PM: success run graphql queries — 0.003 s
10:36:53 PM: success write out page data — 0.003 s
10:36:53 PM: success write out redirect data — 0.001 s
10:36:53 PM: success onPostBootstrap — 0.001 s
10:36:53 PM: 
10:36:53 PM: info bootstrap finished - 1.905 s
10:36:54 PM: 
10:36:58 PM: success Building CSS — 5.702 s
10:37:09 PM: success Building production JavaScript bundles — 10.793 s
10:37:12 PM: 
10:37:12 PM: error Building static HTML for pages failed

See our docs page on debugging HTML builds for help https://goo.gl/yL9lND
10:37:12 PM: 

  Error: Module not found: Error: Cannot resolve module 'sharedComponents/Navbar  ' in /opt/build/repo/src/pages
  resolve module sharedComponents/Navbar in /opt/build/repo/src/pages
    looking for modules in /opt/build/repo/node_modules
      /opt/build/repo/node_modules/sharedComponents doesn't exist (module as dir  ectory)
    looking for modules in /opt/build/repo/node_modules
      /opt/build/repo/node_modules/sharedComponents doesn't exist (module as dir  ectory)
    looking for modules in /opt/build/repo/node_modules
      /opt/build/repo/node_modules/sharedComponents doesn't exist (module as dir  ectory)
    looking for modules in /opt/build/repo/node_modules
      /opt/build/repo/node_modules/sharedComponents doesn't exist (module as dir  ectory)
    looking for modules in /opt/build/repo/node_modules
      /opt/build/repo/node_modules/sharedComponents doesn't exist (module as dir  ectory)
    looking for modules in /opt/build/repo/node_modules
      /opt/build/repo/node_modules/sharedComponents doesn't exist (module as dir  ectory)
    looking for modules in /opt/build/repo/node_modules
      /opt/build/repo/node_modules/sharedComponents doesn't exist (module as dir  ectory)
    looking for modules in /opt/build/repo/node_modules/gatsby/node_modules
      /opt/build/repo/node_modules/gatsby/node_modules/sharedComponents doesn't   exist (module as directory)
    looking for modules in /opt/build/repo/node_modules/gatsby/node_modules
      /opt/build/repo/node_modules/gatsby/node_modules/sharedComponents doesn't   exist (module as directory)
    looking for modules in /opt/build/repo/node_modules/gatsby/node_modules
      /opt/build/repo/node_modules/gatsby/node_modules/sharedComponents doesn't   exist (module as directory)
    looking for modules in /opt/build/repo/node_modules/gatsby/node_modules
      /opt/build/repo/node_modules/gatsby/node_modules/sharedComponents doesn't   exist (module as directory)
    looking for modules in /opt/build/repo/node_modules/gatsby/node_modules
      /opt/build/repo/node_modules/gatsby/node_modules/sharedComponents doesn't   exist (module as directory)
    looking for modules in /opt/build/repo/node_modules/gatsby/node_modules
      /opt/build/repo/node_modules/gatsby/node_modules/sharedComponents doesn't   exist (module as directory)
    looking for modules in /opt/build/repo/src
      resolve 'file' or 'directory' Navbar in /opt/build/repo/src/sharedComponen  ts
        resolve file
          /opt/build/repo/src/sharedComponents/Navbar doesn't exist
          /opt/build/repo/src/sharedComponents/Navbar.js doesn't exist
          /opt/build/repo/src/sharedComponents/Navbar.jsx doesn't exist
        resolve directory
          /opt/build/repo/src/sharedComponents/Navbar doesn't exist (directory d  efault file)
          /opt/build/repo/src/sharedComponents/Navbar/package.json doesn't exist   (directory description file)
  [/opt/build/repo/node_modules/sharedComponents]
  [/opt/build/repo/node_modules/sharedComponents]
  [/opt/build/repo/node_modules/sharedComponents]
  [/opt/build/repo/node_modules/sharedComponents]
  [/opt/build/repo/node_modules/sharedComponents]
  [/opt/build/repo/node_modules/sharedComponents]
  [/opt/build/repo/node_modules/sharedComponents]
  [/opt/build/repo/node_modules/gatsby/node_modules/sharedComponents]
  [/opt/build/repo/node_modules/gatsby/node_modules/sharedComponents]
  [/opt/build/repo/node_modules/gatsby/node_modules/sharedComponents]
  [/opt/build/repo/node_modules/gatsby/node_modules/sharedComponents]
  [/opt/build/repo/node_modules/gatsby/node_modules/sharedComponents]
  [/opt/build/repo/node_modules/gatsby/node_modules/sharedComponents]
  [/opt/build/repo/src/sharedComponents/Navbar]
  [/opt/build/repo/src/sharedComponents/Navbar.js]
  [/opt/build/repo/src/sharedComponents/Navbar.jsx]
   @ ./src/pages/index.js 25:14-48
10:37:13 PM: Cached NPM modules
10:37:13 PM: Saved Cache Directory
10:37:13 PM: Build complete: exit code: 1
10:37:13 PM: Cleaning up docker container
10:37:14 PM: Error running command: Build script returned non-zero exit code: 1
10:37:14 PM: An error occurred while building the site, skipping the deploy and cache refresh.
10:37:14 PM: Build script returned non-zero exit code: 1
10:37:15 PM: Finished processing build request in 1m40.073086378s

Renamed all the components to:

src
src/sharedComponents
src/sharedComponents/Foobar
src/sharedComponents/Foobar/Foobar.js

And fails importing CSS Modules:

  Error: Module not found: Error: Cannot resolve 'file' or 'directory' ./style.m  odule.css in /opt/build/repo/src/sharedComponents/Navbar
  resolve file
    /opt/build/repo/src/sharedComponents/Navbar/style.module.css doesn't exist
    /opt/build/repo/src/sharedComponents/Navbar/style.module.css.js doesn't exis  t
    /opt/build/repo/src/sharedComponents/Navbar/style.module.css.jsx doesn't exi  st
  resolve directory
    /opt/build/repo/src/sharedComponents/Navbar/style.module.css doesn't exist (  directory default file)
    /opt/build/repo/src/sharedComponents/Navbar/style.module.css/package.json do  esn't exist (directory description file)
  [/opt/build/repo/src/sharedComponents/Navbar/style.module.css]
  [/opt/build/repo/src/sharedComponents/Navbar/style.module.css.js]
  [/opt/build/repo/src/sharedComponents/Navbar/style.module.css.jsx]
   @ ./src/sharedComponents/Navbar/Navbar.js 13:19-48
11:15:07 PM: Cached NPM modules
11:15:07 PM: Saved Cache Directory
11:15:07 PM: Build complete: exit code: 1
11:15:07 PM: Cleaning up docker container
11:15:08 PM: Error running command: Build script returned non-zero exit code: 1
11:15:08 PM: An error occurred while building the site, skipping the deploy and cache refresh.
11:15:08 PM: Build script returned non-zero exit code: 1
11:15:09 PM: Finished processing build request in 1m18.633135826s

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
heldridacommented, Nov 13, 2017

Ok, when the directories were renamed in MacOS the repo kept the previous directory names since they are different (case-sensitive). Fixed in the Ubuntu box and pushed and is now working. I’m going to try to re-rename back to /src/sharedComponent/Foobar/index.js to see if it breaks, as Netlify doesn’t seem to support Folder as Filename

src/sharedComponents/Navbar and

src/sharedComponents/navbar
src/sharedComponents/navbar/style.module.css
4reactions
heldridacommented, Mar 29, 2019

@mddanishyusuf the issue above was related to directory and filenames. You need to test your build in a Linux VM, to see that the problems are related to case insensitivity in your original file system!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Build Fails: webpack config.resolve.alias was incorrectly ...
I'm constantly getting a failed build because of 'webpack config.resolve.alias was incorrectly overridden.' (I think… I'm new to all of this).
Read more >
Netlify - Gatsby alias imports not working - Stack Overflow
No issues. Once I try to deploy/build with Netlify, I get this issue with alias.
Read more >
Troubleshooting Common Errors - Gatsby
If you encounter a webpack error that says Generating SSR bundle failed after installing a plugin and trying to run gatsby develop or...
Read more >
Error on Netlify build, yarn rw build succeeds?
Netlify build output ERROR in ./src/components/ChCustomersCell/ChCustomersCell.tsx 9:0-51 Module not found: Error: Can't resolve '.
Read more >
Fix "package esbuild-linux-64 could not be found" error on ...
The last thing I tried was to delete package-lock.json entirely and commit that. Without the lock file, Netlify was able to install the...
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