Home
Support Forums

Deploy error - ModuleNotFoundError: Can't resolve 'mssql'

Site:
https://app.netlify.com/sites/lashes-west-llc

I’m getting a “Module not found” error when deploying to Netlify. Everything works fine when I run this locally. This is a React app with a back-end API. The error seems to be referencing these dependencies:

in the React app package.json:
“netlify-lambda”: “^2.0.15”,

In the API package.json (in the \src\api folder):
“mssql”: “^7.3.0”,

The error occurs when I add this line in the api/server.js file:
var sql = require(‘mssql’);

I’ve seen lots of articles that talk about case sensitivity, I’ve tried every case variation of ‘mssql’ I can think of with the same results. Everything works fine locally, the error occurs when I deploy with the mssql require line.

netlify.toml file:
[build]
functions = “functions”
publish = “build”
[[redirects]]
from = “/*”
to = “/index.html”
status = 200

Deploy log:
1:12:33 PM: Build ready to start
1:12:35 PM: build-image version: 73def8bb10593b9b818f44989a75ea508018ccb7 (focal)
1:12:35 PM: build-image tag: v4.5.2
1:12:35 PM: buildbot version: e07f38cea73012d29c839c78dec87335277fe704
1:12:35 PM: Fetching cached dependencies
1:12:35 PM: Starting to download cache of 335.5MB
1:12:37 PM: Finished downloading cache in 1.512647026s
1:12:37 PM: Starting to extract cache
1:12:52 PM: Finished extracting cache in 15.063619951s
1:12:52 PM: Finished fetching cache in 16.646885368s
1:12:52 PM: Starting to prepare the repo for build
1:12:52 PM: Preparing Git Reference refs/heads/master
1:12:54 PM: Parsing package.json dependencies
1:12:55 PM: Different functions path detected, going to use the one specified in the Netlify configuration file: ‘functions’ versus ‘’ in the Netlify UI
1:12:55 PM: Starting build script
1:12:55 PM: Installing dependencies
1:12:55 PM: Python version set to 2.7
1:12:55 PM: Started restoring cached node version
1:12:57 PM: Finished restoring cached node version
1:12:58 PM: v16.13.1 is already installed.
1:12:59 PM: Now using node v16.13.1 (npm v8.1.2)
1:12:59 PM: Started restoring cached build plugins
1:12:59 PM: Finished restoring cached build plugins
1:12:59 PM: Attempting ruby version 2.7.2, read from environment
1:13:01 PM: Using ruby version 2.7.2
1:13:01 PM: Using PHP version 8.0
1:13:01 PM: Started restoring cached yarn cache
1:13:16 PM: Finished restoring cached yarn cache
1:13:17 PM: No yarn workspaces detected
1:13:17 PM: Started restoring cached node modules
1:13:17 PM: Finished restoring cached node modules
1:13:17 PM: Installing NPM modules using Yarn version 1.22.10
1:13:18 PM: yarn install v1.22.10
1:13:18 PM: [1/4] Resolving packages…
1:13:19 PM: success Already up-to-date.
1:13:19 PM: Done in 1.29s.
1:13:19 PM: NPM modules installed using Yarn
1:13:19 PM: Started restoring cached go cache
1:13:19 PM: Finished restoring cached go cache
1:13:20 PM: go version go1.16.5 linux/amd64
1:13:20 PM: go version go1.16.5 linux/amd64
1:13:20 PM: Installing missing commands
1:13:20 PM: Verify run directory
1:13:22 PM: ​
1:13:22 PM: ────────────────────────────────────────────────────────────────
1:13:22 PM: Netlify Build
1:13:22 PM: ────────────────────────────────────────────────────────────────
1:13:22 PM: ​
1:13:22 PM: ❯ Version
1:13:22 PM: @netlify/build 26.0.2
1:13:22 PM: ​
1:13:22 PM: ❯ Flags
1:13:22 PM: baseRelDir: true
1:13:22 PM: buildId: 61ccb32146ce570007c92299
1:13:22 PM: deployId: 61ccb32146ce570007c9229b
1:13:22 PM: ​
1:13:22 PM: ❯ Current directory
1:13:22 PM: /opt/build/repo
1:13:22 PM: ​
1:13:22 PM: ❯ Config file
1:13:22 PM: /opt/build/repo/netlify.toml
1:13:22 PM: ​
1:13:22 PM: ❯ Context
1:13:22 PM: production
1:13:22 PM: ​
1:13:22 PM: ────────────────────────────────────────────────────────────────
1:13:22 PM: 1. Build command from Netlify app
1:13:22 PM: ────────────────────────────────────────────────────────────────
1:13:22 PM: ​
1:13:22 PM: $ yarn build
1:13:22 PM: yarn run v1.22.10
1:13:22 PM: $ run-p build:**
1:13:23 PM: $ netlify-lambda build src/api
1:13:23 PM: $ react-scripts build
1:13:24 PM: netlify-lambda: Building functions
1:13:25 PM: ModuleNotFoundError: Module not found: Error: Can’t resolve ‘mssql’ in ‘/opt/build/repo/src/api’ at /opt/build/repo/node_modules/netlify-lambda/node_modules/webpack/lib/Compilation.js:925:10
1:13:25 PM: at /opt/build/repo/node_modules/netlify-lambda/node_modules/webpack/lib/NormalModuleFactory.js:401:22
1:13:25 PM: at /opt/build/repo/node_modules/netlify-lambda/node_modules/webpack/lib/NormalModuleFactory.js:130:21
1:13:25 PM: at /opt/build/repo/node_modules/netlify-lambda/node_modules/webpack/lib/NormalModuleFactory.js:224:22
1:13:25 PM: at /opt/build/repo/node_modules/neo-async/async.js:2830:7
1:13:25 PM: at /opt/build/repo/node_modules/neo-async/async.js:6877:13
1:13:25 PM: at /opt/build/repo/node_modules/netlify-lambda/node_modules/webpack/lib/NormalModuleFactory.js:214:25
1:13:25 PM: at /opt/build/repo/node_modules/enhanced-resolve/lib/Resolver.js:213:14
1:13:25 PM: at /opt/build/repo/node_modules/enhanced-resolve/lib/Resolver.js:285:5
1:13:25 PM: at eval (eval at create (/opt/build/repo/node_modules/tapable/lib/HookCodeFactory.js:33:10), :15:1)
1:13:25 PM: at /opt/build/repo/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:44:7
1:13:25 PM: at /opt/build/repo/node_modules/enhanced-resolve/lib/Resolver.js:285:5
1:13:25 PM: at eval (eval at create (/opt/build/repo/node_modules/tapable/lib/HookCodeFactory.js:33:10), :15:1)
1:13:25 PM: at /opt/build/repo/node_modules/enhanced-resolve/lib/Resolver.js:285:5
1:13:25 PM: at eval (eval at create (/opt/build/repo/node_modules/tapable/lib/HookCodeFactory.js:33:10), :27:1)
1:13:25 PM: at /opt/build/repo/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43
1:13:25 PM: resolve ‘mssql’ in ‘/opt/build/repo/src/api’
1:13:25 PM: Parsed request is a module
1:13:25 PM: using description file: /opt/build/repo/src/api/package.json (relative path: .)
1:13:25 PM: resolve as module
1:13:25 PM: /opt/build/repo/src/api/node_modules doesn’t exist or is not a directory /opt/build/repo/src/node_modules doesn’t exist or is not a directory /opt/build/node_modules doesn’t exist or is not a directory /opt/node_modules doesn’t exist or is not a directory /node_modules doesn’t exist or is not a directory looking for modules in /opt/build/repo/node_modules
1:13:25 PM: using description file: /opt/build/repo/package.json (relative path: ./node_modules)
1:13:25 PM: using description file: /opt/build/repo/package.json (relative path: ./node_modules/mssql)
1:13:25 PM: no extension
1:13:25 PM: /opt/build/repo/node_modules/mssql doesn’t exist .wasm
1:13:25 PM: /opt/build/repo/node_modules/mssql.wasm doesn’t exist .mjs
1:13:25 PM: /opt/build/repo/node_modules/mssql.mjs doesn’t exist .js
1:13:25 PM: /opt/build/repo/node_modules/mssql.js doesn’t exist .json
1:13:25 PM: /opt/build/repo/node_modules/mssql.json doesn’t exist .ts
1:13:25 PM: /opt/build/repo/node_modules/mssql.ts doesn’t exist as directory
1:13:25 PM: /opt/build/repo/node_modules/mssql doesn’t existerror Command failed with exit code 1.
1:13:25 PM: info Visit yarn run | Yarn for documentation about this command.
1:13:25 PM: ERROR: “build:lambda” exited with 1.
1:13:25 PM: error Command failed with exit code 1.
1:13:25 PM: info Visit yarn run | Yarn for documentation about this command.
1:13:25 PM: ​
1:13:25 PM: ────────────────────────────────────────────────────────────────
1:13:25 PM: “build.command” failed
1:13:25 PM: ────────────────────────────────────────────────────────────────
1:13:25 PM: ​
1:13:25 PM: Error message
1:13:25 PM: Command failed with exit code 1: yarn build
1:13:25 PM: ​
1:13:25 PM: Error location
1:13:25 PM: In Build command from Netlify app:
1:13:25 PM: yarn build
1:13:25 PM: ​
1:13:25 PM: Resolved config
1:13:25 PM: build:
1:13:25 PM: command: yarn build
1:13:25 PM: commandOrigin: ui
1:13:25 PM: publish: /opt/build/repo/build
1:13:25 PM: publishOrigin: config
1:13:25 PM: functionsDirectory: /opt/build/repo/functions
1:13:25 PM: redirects:
1:13:26 PM: - from: /* status: 200 to: /index.html redirectsOrigin: configCaching artifacts
1:13:26 PM: Started saving node modules
1:13:26 PM: Finished saving node modules
1:13:26 PM: Started saving build plugins
1:13:26 PM: Finished saving build plugins
1:13:26 PM: Started saving yarn cache
1:13:40 PM: Finished saving yarn cache
1:13:40 PM: Started saving pip cache
1:13:40 PM: Finished saving pip cache
1:13:40 PM: Started saving emacs cask dependencies
1:13:40 PM: Finished saving emacs cask dependencies
1:13:40 PM: Started saving maven dependencies
1:13:40 PM: Finished saving maven dependencies
1:13:40 PM: Started saving boot dependencies
1:13:40 PM: Finished saving boot dependencies
1:13:40 PM: Started saving rust rustup cache
1:13:40 PM: Finished saving rust rustup cache
1:13:40 PM: Started saving go dependencies
1:13:40 PM: Finished saving go dependencies
1:13:40 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:13:40 PM: Creating deploy upload records
1:13:41 PM: Failing build: Failed to build site
1:13:41 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
1:13:41 PM: Finished processing build request in 1m5.552440971s

Hi @DaveP

Welcome to the forums

If the build is happening at the root of the repository (at is appears it is) then required modules need to exists in the package.json at the root of the repository.

If you are building separate parts you might need a build command something more like

cd src/api && npm i && cd .. && npm run build

to build the api prior to the main project (this command probably won’t work.) However this is only a guess as I don’t know what you are building (or trying to build). If you can share more details, or even better the repository you are deploying from, a more specific answer may come surface.

That worked, thanks!

mssql was installed in the /src/api package.json, and so I installed it in the root package.json as well. It did then require that I also install the “encoding” package in the root, which I did…not sure why it required encoding, but it’s all working now.

Dave Petersen

1 Like