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

Netlify fails to resolve alias and build fails #2897

Closed
heldrida opened this issue Nov 12, 2017 · 9 comments · May be fixed by tejzpr/gatsby#61
Closed

Netlify fails to resolve alias and build fails #2897

heldrida opened this issue Nov 12, 2017 · 9 comments · May be fixed by tejzpr/gatsby#61

Comments

@heldrida
Copy link

heldrida commented Nov 12, 2017

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 <[email protected]>",
  "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 [email protected]: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 [email protected]: 🙌  Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!
10:36:32 PM: 
> [email protected] 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:  [email protected] No repository field.
10:36:50 PM: npm WARN
10:36:50 PM:  optional
10:36:50 PM:  SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
10:36:50 PM: npm WARN
10:36:50 PM: 
10:36:51 PM: notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: 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
@KyleAMathews
Copy link
Contributor

Not really sure — I'd keep following up on Linux/Mac differences. Perhaps if you have a Linux VM handy, start playing around with the site there.

@heldrida
Copy link
Author

Ok, I had a quick look and it does fail on Linux (Ubuntu 12.04). I'm going to keep doing some tests.

  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

*btw run into this problem #1905

@heldrida
Copy link
Author

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

@KyleAMathews
Copy link
Contributor

Ah cool :-)

Yeah I always use lowercase names as I've this issue way too many times haha :-D

@heldrida
Copy link
Author

For future readers, the problem is related to Macos case-insensitive FS (in case you didn't change that during format). I did run into this issue before, but webpack 2 usually throws an error, which will have in gatsby in the future when webpack is upgraded I guess.

So, renamed:

src
src/sharedComponents
src/sharedComponents/Navbar/Navbar.js

to

src
src/sharedComponents
src/sharedComponents/Navbar/index.js

@mddanishyusuf
Copy link

@heldrida But when I run the command locally it builds successfully but not working on netlify.

@heldrida
Copy link
Author

@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!

@tobob
Copy link

tobob commented Aug 18, 2020

I think that the best solution, in this case, is to change files name with _ prefix, commit, then remove all the prefixes from failed files - it will allow iOS to track changes in names

#14684 (comment)

@William-Schutte
Copy link

For those still having this issue on macs, one other way to find the "true" capitalization of your filenames is to check the names on GitHub. You can then edit the filename directly on GH and pull the changes. Although nothing will change in your file system, your deploy to Netlify should work.

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

Successfully merging a pull request may close this issue.

5 participants