Module not found: Error: Can't resolve

site name: hawkbone.netlifu.app
custom domain: hawkbone.com
issue:

I’m unable to get a successful build on Netlify. It builds without issue on my machine with old and fresh repo clone. The module that it can’t find is imported with import './app.scss'; and sits in the same directory as the file trying to import it. I have a webpack build rule for .scss files to use ‘style-loader’, ‘css-loader’, ‘postcss-loader’, and ‘sass-loader’.

The site I’m trying to build is in the ./app folder of my repo.

Also, the webpack output in the Netlify build log is different than what I see locally. Why is that?

I thought maybe it wasn’t installing my devDependencies so I moved them all as main dependencies (though I did see another post saying the default NODE_ENV is development)

Deploy Settings:
base directory: app
build command: npm run build
publish directory: app/dist
builds: active

Local versions:
node: 12.17.0
npm: 6.14.5

Build Log:
8:31:14 PM: Build ready to start
8:31:16 PM: build-image version: 3031d4c9e432fd7016f6279fc9ad706f9205d845
8:31:16 PM: build-image tag: v3.3.17
8:31:16 PM: buildbot version: 1f35b3abd6e2bf5230d8edf68072840fdec1513f
8:31:16 PM: Fetching cached dependencies
8:31:16 PM: Starting to download cache of 254.3KB
8:31:16 PM: Finished downloading cache in 74.059333ms
8:31:16 PM: Starting to extract cache
8:31:16 PM: Failed to fetch cache, continuing with build
8:31:16 PM: Starting to prepare the repo for build
8:31:17 PM: No cached dependencies found. Cloning fresh repo
8:31:17 PM: git clone https://github.com/dancvogel/hawkbone
8:31:18 PM: Preparing Git Reference refs/heads/master
8:31:19 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: ‘app/dist’ versus ‘dist’ in the Netlify UI
8:31:19 PM: Starting build script
8:31:19 PM: Installing dependencies
8:31:19 PM: Python version set to 2.7
8:31:20 PM: v12.18.0 is already installed.
8:31:20 PM: Now using node v12.18.0 (npm v6.14.4)
8:31:20 PM: Started restoring cached build plugins
8:31:20 PM: Finished restoring cached build plugins
8:31:20 PM: Attempting ruby version 2.7.1, read from environment
8:31:22 PM: Using ruby version 2.7.1
8:31:22 PM: Using PHP version 5.6
8:31:22 PM: 5.2 is already installed.
8:31:22 PM: Using Swift version 5.2
8:31:22 PM: Started restoring cached node modules
8:31:22 PM: Finished restoring cached node modules
8:31:22 PM: Installing NPM modules using NPM version 6.14.4
8:31:44 PM: > node-sass@4.14.1 install /opt/build/repo/app/node_modules/node-sass
8:31:44 PM: > node scripts/install.js
8:31:44 PM: Downloading binary from https://github.com/sass/node-sass/releases/download/v4.14.1/linux-x64-72_binding.node
8:31:45 PM: Download complete
8:31:45 PM: Binary saved to /opt/build/repo/app/node_modules/node-sass/vendor/linux-x64-72/binding.node
8:31:45 PM: Caching binary to /opt/buildhome/.npm/node-sass/4.14.1/linux-x64-72_binding.node
8:31:45 PM: > core-js@2.6.11 postinstall /opt/build/repo/app/node_modules/core-js
8:31:45 PM: > node -e “try{require(’./postinstall’)}catch(e){}”
8:31:45 PM: > core-js-pure@3.6.5 postinstall /opt/build/repo/app/node_modules/core-js-pure
8:31:45 PM: > node -e “try{require(’./postinstall’)}catch(e){}”
8:31:45 PM: > node-sass@4.14.1 postinstall /opt/build/repo/app/node_modules/node-sass
8:31:45 PM: > node scripts/build.js
8:31:46 PM: Binary found at /opt/build/repo/app/node_modules/node-sass/vendor/linux-x64-72/binding.node
8:31:46 PM: Testing binary
8:31:46 PM: Binary is fine
8:31:47 PM: npm WARN app@1.2.0 No repository field.
8:31:47 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/watchpack/node_modules/fsevents):
8:31:47 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
8:31:47 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/fsevents):
8:31:47 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
8:31:47 PM: added 1246 packages from 602 contributors and audited 1251 packages in 24.134s
8:31:48 PM: 50 packages are looking for funding
8:31:48 PM: run npm fund for details
8:31:48 PM: found 0 vulnerabilities
8:31:48 PM: NPM modules installed
8:31:48 PM: Started restoring cached go cache
8:31:48 PM: Finished restoring cached go cache
8:31:48 PM: go version go1.14.4 linux/amd64
8:31:48 PM: go version go1.14.4 linux/amd64
8:31:48 PM: Installing missing commands
8:31:48 PM: Verify run directory
8:31:49 PM: ​
8:31:49 PM: ┌─────────────────────────────┐
8:31:49 PM: │ Netlify Build │
8:31:49 PM: └─────────────────────────────┘
8:31:49 PM: ​
8:31:49 PM: ❯ Version
8:31:49 PM: @netlify/build 2.0.10
8:31:49 PM: ​
8:31:49 PM: ❯ Flags
8:31:49 PM: deployId: 5ef41a82b300be8be0c1beb3
8:31:49 PM: mode: buildbot
8:31:49 PM: ​
8:31:49 PM: ❯ Current directory
8:31:49 PM: /opt/build/repo/app
8:31:49 PM: ​
8:31:49 PM: ❯ Config file
8:31:49 PM: No config file was defined: using default values.
8:31:49 PM: ​
8:31:49 PM: ❯ Context
8:31:49 PM: production
8:31:49 PM: ​
8:31:49 PM: ┌────────────────────────────────┐
8:31:49 PM: │ 1. Build command from settings │
8:31:49 PM: └────────────────────────────────┘
8:31:49 PM: ​
8:31:49 PM: $ npm run build
8:31:49 PM: > app@1.2.0 build /opt/build/repo/app
8:31:49 PM: > webpack --config webpack.prod.js --env.minor
8:31:50 PM: [AIV] : info : Auto inject version started
8:31:50 PM: clean-webpack-plugin: /opt/build/repo/app/dist has been removed.
8:31:50 PM: (node:1347) DeprecationWarning: Tapable.plugin is deprecated. Use new API on .hooks instead
8:31:50 PM: [AIV] : info : autoIncVersion : new version : 1.3.0
8:31:50 PM: [AIV] : info : package.json updated!
8:32:11 PM: Hash: b55669811e0e12136671
8:32:11 PM: Version: webpack 4.43.0
8:32:11 PM: Time: 21042ms
8:32:11 PM: Built at: 06/25/2020 3:32:11 AM
8:32:11 PM: 26 assets
8:32:11 PM: Entrypoint main = runtime~main.a808c75bfe039e157e19.js runtime~main.a808c75bfe039e157e19.js.map vendors~main.dbfbdccaa68adba3a576.js vendors~main.dbfbdccaa68adba3a576.js.map main.96e0478c223bdb370746.js main.96e0478c223bdb370746.js.map
8:32:11 PM: [8] ./src/services/uiStrings.js 1.62 KiB {2} [built]
8:32:11 PM: [16] ./src/services/appSettings.js 416 bytes {2} [built]
8:32:11 PM: [25] ./node_modules/history/esm/history.js + 2 modules 30.6 KiB {4} [built]
8:32:11 PM: | 3 modules
8:32:11 PM: [40] ./src/services/auth.js 2.37 KiB {2} [built]
8:32:11 PM: [66] ./src/contexts/InventoryProvider.js + 2 modules 19.8 KiB {2} [built]
8:32:11 PM: | ./src/contexts/InventoryProvider.js 12.3 KiB [built]
8:32:11 PM: | ./src/services/api/productsApi.js 2.11 KiB [built]
8:32:11 PM: | ./src/services/api/api.js 5.45 KiB [built]
8:32:11 PM: [71] (webpack)/buildin/global.js 472 bytes {4} [built]
8:32:11 PM: [148] ./src/shared/Button/index.js + 1 modules 855 bytes {2} [built]
8:32:11 PM: | ./src/shared/Button/index.js 35 bytes [built]
8:32:11 PM: | ./src/shared/Button/Button.jsx 810 bytes [built]
8:32:11 PM: [225] multi @babel/polyfill ./src/index.js 40 bytes {2} [built]
8:32:11 PM: [563] ./src/client/ClientApp.scss 1.35 KiB {2} [built]
8:32:11 PM: [564] ./node_modules/css-loader/dist/cjs.js!./node_modules/postcss-loader/src!./node_modules/sass-loader/dist/cjs.js!./src/client/ClientApp.scss 605 bytes {2} [built]
8:32:11 PM: [567] ./src/index.js + 9 modules 15.4 KiB {2} [built]
8:32:11 PM: | ./src/index.js 181 bytes [built]
8:32:11 PM: | ./src/App.jsx 2.37 KiB [built]
8:32:11 PM: | ./src/client/ClientApp.jsx 1.49 KiB [built]
8:32:11 PM: | ./src/admin/AdminApp.jsx 5.46 KiB [built]
8:32:11 PM: | ./src/services/routes.js 1.37 KiB [built]
8:32:11 PM: | + 5 hidden modules
8:32:11 PM: [588] ./src/admin/components/InventoryManagement/index.js + 3 modules 14.3 KiB {5} [built]
8:32:11 PM: | 4 modules
8:32:11 PM: [589] ./src/client/components/pages/Shop/index.js + 2 modules 3.25 KiB {1} [built]
8:32:11 PM: | 3 modules
8:32:11 PM: [590] ./src/client/components/pages/Cart/index.js + 1 modules 2.93 KiB {6} [built]
8:32:11 PM: | 2 modules
8:32:11 PM: [591] ./src/admin/components/InventoryForm.jsx + 1 modules 11.4 KiB {0} [built]
8:32:11 PM: | 2 modules
8:32:11 PM: + 577 hidden modules
8:32:11 PM: ERROR in ./src/App.jsx
8:32:11 PM: Module not found: Error: Can’t resolve ‘./app.scss’ in ‘/opt/build/repo/app/src’ @ ./src/App.jsx 9:0-20
8:32:11 PM: @ ./src/index.js
8:32:11 PM: @ multi @babel/polyfill ./src/index.js
8:32:11 PM: Child html-webpack-plugin for “index.html”:
8:32:11 PM: 3 assets
8:32:11 PM: Entrypoint undefined = index.html
8:32:11 PM: [0] ./node_modules/html-webpack-plugin/lib/loader.js!./public/index.html 1.17 KiB {0} [built]
8:32:11 PM: [2] (webpack)/buildin/global.js 472 bytes {0} [built]
8:32:11 PM: [3] (webpack)/buildin/module.js 497 bytes {0} [built]
8:32:11 PM: + 1 hidden module
8:32:11 PM: npm ERR! code ELIFECYCLE
8:32:11 PM: npm ERR! errno 2
8:32:11 PM: npm ERR! app@1.2.0 build: webpack --config webpack.prod.js --env.minor
8:32:11 PM: npm ERR! Exit status 2
8:32:11 PM: npm ERR!
8:32:11 PM: npm ERR! Failed at the app@1.2.0 build script.
8:32:11 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
8:32:11 PM: npm ERR! A complete log of this run can be found in:
8:32:11 PM: npm ERR! /opt/buildhome/.npm/_logs/2020-06-25T03_32_11_990Z-debug.log
8:32:12 PM: ​
8:32:12 PM: ┌─────────────────────────────┐
8:32:12 PM: │ “build.command” failed │
8:32:12 PM: └─────────────────────────────┘
8:32:12 PM: ​
8:32:12 PM: Error message
8:32:12 PM: Command failed with exit code 2: npm run build
8:32:12 PM: ​
8:32:12 PM: Error location
8:32:12 PM: In Build command from settings:
8:32:12 PM: npm run build
8:32:12 PM: ​
8:32:12 PM: Resolved config
8:32:12 PM: build:
8:32:12 PM: base: /opt/build/repo/app
8:32:12 PM: command: npm run build
8:32:12 PM: publish: /opt/build/repo/app/dist
8:32:12 PM: Caching artifacts
8:32:12 PM: Started saving node modules
8:32:12 PM: Finished saving node modules
8:32:12 PM: Started saving build plugins
8:32:12 PM: Finished saving build plugins
8:32:12 PM: Started saving pip cache
8:32:18 PM: Finished saving pip cache
8:32:18 PM: Started saving emacs cask dependencies
8:32:18 PM: Finished saving emacs cask dependencies
8:32:18 PM: Started saving maven dependencies
8:32:18 PM: Finished saving maven dependencies
8:32:18 PM: Started saving boot dependencies
8:32:18 PM: Finished saving boot dependencies
8:32:18 PM: Started saving go dependencies
8:32:18 PM: Finished saving go dependencies
8:32:20 PM: Error running command: Build script returned non-zero exit code: 1
8:32:20 PM: Failing build: Failed to build site
8:32:20 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 1
8:32:20 PM: Finished processing build request in 1m4.258227555s

More things tried:

  1. using the netlify cli at the root of my repo locally i can run netlify build and get a successful build

  2. I thought maybe the netlify was doing an npm install from the repo root and not from the base directory so I added a package.json with a postinstall script to “cd app && npm install” - didn’t help

hi there the above is the likely culprit.

is this applicable at all?

Well, seems i had committed that file to my repo originally as uppercase App.scss and must have later decided it should be lower case. :sob: Fixed the casing in my repo and it fixed the build. Thanks for the help!

Congrats on solving it!!