Express program buiild failed

Hi, I run into a problem recently, my express service worked fine on netlify before, and last commit I changed some business code, then cannot build success ever!

This is my site: tc-backend.netlify.app
And below is the build log(remove some content because of word count limit), I have checked it, found error when netlify-lambda build express, seems is about ‘webpack’, but this is a nodejs service, I haven’t install ‘webpack’, and the package-lock file shows thenetlify-lambda package required ‘webpack’, now I have no clue how to fix this. can anyone please lend me a hand?

...
4:38:30 PM: $ npm install && npm run build
4:38:32 PM: npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
4:38:33 PM: npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
4:38:34 PM: npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
4:38:35 PM: npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
4:38:36 PM: npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
4:38:36 PM: npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
4:38:38 PM: added 839 packages, changed 13 packages, and audited 853 packages in 7s
4:38:38 PM: 41 packages are looking for funding
4:38:38 PM:   run `npm fund` for details
4:38:38 PM: 5 high severity vulnerabilities
4:38:38 PM: To address all issues, run:
4:38:38 PM:   npm audit fix
4:38:38 PM: Run `npm audit` for details.
4:38:38 PM: > training-course-backend@0.0.1 build
4:38:38 PM: > netlify-lambda build express
4:38:38 PM: netlify-lambda: Building functions
4:38:47 PM: [
4:38:47 PM:   ModuleParseError: Module parse failed: Unexpected token (10:37)
4:38:47 PM:   You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
4:38:47 PM:   |         "x-amz-sso_bearer_token": input.accessToken,
4:38:47 PM:   |     });
4:38:47 PM:   >     const resolvedPath = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + "/federation/credentials";
4:38:47 PM:   |     const query = map({
4:38:47 PM:   |         role_name: [, input.roleName],
4:38:47 PM:       at handleParseError (/opt/build/repo/node_modules/webpack/lib/NormalModule.js:469:19)
4:38:47 PM:       at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:503:5
4:38:47 PM:       at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:358:12
4:38:47 PM:       at /opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:373:3
4:38:47 PM:       at iterateNormalLoaders (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
4:38:47 PM:       at Array.<anonymous> (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
4:38:47 PM:       at Storage.finished (/opt/build/repo/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
4:38:47 PM:       at /opt/build/repo/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
4:38:47 PM:       at /opt/build/repo/node_modules/graceful-fs/graceful-fs.js:123:16
4:38:47 PM:       at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3),
4:38:47 PM:   ModuleParseError: Module parse failed: Unexpected token (10:50)
4:38:47 PM:   You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
4:38:47 PM:   |         }, { ...config }, context);
4:38:47 PM:   |         context.endpointV2 = endpoint;
4:38:47 PM:   >         context.authSchemes = endpoint.properties?.authSchemes;
4:38:47 PM:   |         const authScheme = context.authSchemes?.[0];
4:38:47 PM:   |         if (authScheme) {
4:38:47 PM:       at handleParseError (/opt/build/repo/node_modules/webpack/lib/NormalModule.js:469:19)
4:38:47 PM:       at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:503:5
4:38:47 PM:       at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:358:12
4:38:47 PM:       at /opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:373:3
4:38:47 PM:       at iterateNormalLoaders (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
4:38:47 PM:       at Array.<anonymous> (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
4:38:47 PM:       at Storage.finished (/opt/build/repo/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
4:38:47 PM:       at /opt/build/repo/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
4:38:47 PM:       at /opt/build/repo/node_modules/graceful-fs/graceful-fs.js:123:16
4:38:47 PM:       at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3),
4:38:47 PM:   ModuleParseError: Module parse failed: Unexpected token (11:28)
4:38:47 PM:   You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
4:38:47 PM:   |         this.lastTimestamp = 0;
4:38:47 PM:   |         this.timeWindow = 0;
4:38:47 PM:   >         this.beta = options?.beta ?? 0.7;
4:38:47 PM:   |         this.minCapacity = options?.minCapacity ?? 1;
4:38:47 PM:   |         this.minFillRate = options?.minFillRate ?? 0.5;
4:38:47 PM:       at handleParseError (/opt/build/repo/node_modules/webpack/lib/NormalModule.js:469:19)
4:38:48 PM: Creating deploy upload records
4:38:47 PM:       at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:503:5
4:38:47 PM:       at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:358:12
4:38:47 PM:       at /opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:373:3
4:38:47 PM:       at iterateNormalLoaders (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
4:38:47 PM:       at Array.<anonymous> (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
4:38:49 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
4:38:47 PM:       at Storage.finished (/opt/build/repo/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
4:38:47 PM:       at /opt/build/repo/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
4:38:47 PM:       at /opt/build/repo/node_modules/graceful-fs/graceful-fs.js:123:16
4:38:47 PM:       at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3),
4:38:47 PM:   ModuleParseError: Module parse failed: Unexpected token (13:36)
4:38:47 PM:   You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
4:38:47 PM:   |         this.maxAttemptsProvider = maxAttemptsProvider;
4:38:47 PM:   |         this.mode = RETRY_MODES.STANDARD;
4:38:47 PM:   >         this.retryDecider = options?.retryDecider ?? defaultRetryDecider;
4:38:47 PM:   |         this.delayDecider = options?.delayDecider ?? defaultDelayDecider;
4:38:47 PM:   |         this.retryQuota = options?.retryQuota ?? getDefaultRetryQuota(INITIAL_RETRY_TOKENS);
4:38:47 PM:       at handleParseError (/opt/build/repo/node_modules/webpack/lib/NormalModule.js:469:19)
4:38:47 PM:       at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:503:5
4:38:47 PM:       at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:358:12
4:38:47 PM:       at /opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:373:3
4:38:47 PM:       at iterateNormalLoaders (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
4:38:47 PM:       at Array.<anonymous> (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
4:38:47 PM:       at Storage.finished (/opt/build/repo/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
4:38:47 PM:       at /opt/build/repo/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
4:38:47 PM:       at /opt/build/repo/node_modules/graceful-fs/graceful-fs.js:123:16
4:38:47 PM:       at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3),
...

4:38:47 PM:   ModuleParseError: Module parse failed: Unexpected token (7:84)
4:38:47 PM:   You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
4:38:47 PM:   | export const getRegionInfo = (region, { useFipsEndpoint = false, useDualstackEndpoint = false, signingService, regionHash, partitionHash, }) => {
4:38:47 PM:   |     const partition = getResolvedPartition(region, { partitionHash });
4:38:47 PM:   >     const resolvedRegion = region in regionHash ? region : partitionHash[partition]?.endpoint ?? region;
4:38:47 PM:   |     const hostnameOptions = { useFipsEndpoint, useDualstackEndpoint };
4:38:47 PM:   |     const regionHostname = getHostnameFromVariants(regionHash[resolvedRegion]?.variants, hostnameOptions);
4:38:47 PM:       at handleParseError (/opt/build/repo/node_modules/webpack/lib/NormalModule.js:469:19)
4:38:47 PM:       at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:503:5
4:38:47 PM:       at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:358:12
4:38:47 PM:       at /opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:373:3
4:38:47 PM:       at iterateNormalLoaders (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
4:38:47 PM:       at Array.<anonymous> (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
4:38:47 PM:       at Storage.finished (/opt/build/repo/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
4:38:47 PM:       at /opt/build/repo/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
4:38:47 PM:       at /opt/build/repo/node_modules/graceful-fs/graceful-fs.js:123:16
4:38:47 PM:       at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3),
4:38:47 PM:   ModuleParseError: Module parse failed: Unexpected token (8:24)
4:38:47 PM:   You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
4:38:47 PM:   |     return {
4:38:47 PM:   |         ...input,
4:38:47 PM:   >         tls: input.tls ?? true,
4:38:47 PM:   |         endpoint: endpoint
4:38:47 PM:   |             ? normalizeProvider(typeof endpoint === "string" ? urlParser(endpoint) : endpoint)
4:38:47 PM:       at handleParseError (/opt/build/repo/node_modules/webpack/lib/NormalModule.js:469:19)
4:38:47 PM:       at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:503:5
4:38:47 PM:       at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:358:12
4:38:47 PM:       at /opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:373:3
4:38:47 PM:       at iterateNormalLoaders (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
4:38:47 PM:       at Array.<anonymous> (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
4:38:47 PM:       at Storage.finished (/opt/build/repo/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
4:38:47 PM:       at /opt/build/repo/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
4:38:47 PM:       at /opt/build/repo/node_modules/graceful-fs/graceful-fs.js:123:16
4:38:47 PM:       at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3),
4:38:47 PM:   ModuleParseError: Module parse failed: Unexpected token (8:30)
4:38:47 PM:   You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
4:38:47 PM:   |         return next(args);
4:38:47 PM:   |     const { headers } = request;
4:38:47 PM:   >     const userAgent = context?.userAgent?.map(escapeUserAgent) || [];
4:38:47 PM:   |     const defaultUserAgent = (await options.defaultUserAgentProvider()).map(escapeUserAgent);
4:38:47 PM:   |     const customUserAgent = options?.customUserAgent?.map(escapeUserAgent) || [];
4:38:47 PM:       at handleParseError (/opt/build/repo/node_modules/webpack/lib/NormalModule.js:469:19)
4:38:47 PM:       at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:503:5
4:38:47 PM:       at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:358:12
4:38:47 PM:       at /opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:373:3
4:38:47 PM:       at iterateNormalLoaders (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
4:38:47 PM:       at Array.<anonymous> (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
4:38:47 PM:       at Storage.finished (/opt/build/repo/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
4:38:47 PM:       at /opt/build/repo/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
4:38:47 PM:       at /opt/build/repo/node_modules/graceful-fs/graceful-fs.js:123:16
4:38:47 PM:       at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3),
4:38:47 PM:   ModuleParseError: Module parse failed: Unexpected token (9:39)
4:38:47 PM:   You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
4:38:47 PM:   |             method: "GET",
4:38:47 PM:   |             ...options,
4:38:47 PM:   >             hostname: options.hostname?.replace(/^\[(.+)\]$/, "$1"),
4:38:47 PM:   |         });
4:38:47 PM:   |         req.on("error", (err) => {
4:38:47 PM:       at handleParseError (/opt/build/repo/node_modules/webpack/lib/NormalModule.js:469:19)
4:38:47 PM:       at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:503:5
4:38:47 PM:       at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:358:12
4:38:47 PM:       at /opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:373:3
4:38:47 PM:       at iterateNormalLoaders (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
4:38:47 PM:       at Array.<anonymous> (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
4:38:47 PM:       at Storage.finished (/opt/build/repo/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
4:38:47 PM:       at /opt/build/repo/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
4:38:47 PM:       at /opt/build/repo/node_modules/graceful-fs/graceful-fs.js:123:16
4:38:47 PM:       at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)
4:38:47 PM: ]
4:38:47 PM: ​
4:38:47 PM: ────────────────────────────────────────────────────────────────
4:38:47 PM:   "build.command" failed                                        
4:38:47 PM: ────────────────────────────────────────────────────────────────
4:38:47 PM: ​
4:38:47 PM:   Error message
4:38:47 PM:   Command failed with exit code 1: npm install && npm run build (https://ntl.fyi/exit-code-1)
4:38:47 PM: ​
4:38:47 PM:   Error location
4:38:47 PM:   In build.command from netlify.toml:
4:38:47 PM:   npm install && npm run build
4:38:47 PM: ​
4:38:47 PM:   Resolved config
4:38:47 PM:   build:
4:38:47 PM:     command: npm install && npm run build
4:38:47 PM:     commandOrigin: config
4:38:47 PM:     environment:
4:38:47 PM:       - MONGO_URL
4:38:47 PM:       - NO_ENV_FILE
4:38:47 PM:     publish: /opt/build/repo
4:38:47 PM:     publishOrigin: default
4:38:47 PM:   functionsDirectory: /opt/build/repo/functions
4:38:47 PM: Caching artifacts
4:38:47 PM: Started saving node modules
...

Heya, lvsong, welcome to the netlify community !

This seems like an issue with your
config maybe, it’s trying to build
netlify functions (read more here) in node_modules, maybe you
misconfigured it ?

Please check your netlify.toml potentially, your functions dir should not be set to node_modules, read more about file-based configuration here :slight_smile:

Thanks for reply so soon!

This is my netlify.toml file:

[build]
  command = "npm install && npm run build"
  functions = "functions"

It works fine before.

Please check my github repository if you may, this is a really tiny project, and I used the simply config for netlify.

Thanks for sharing the repository @lvsong77. Unfortunately it is private. Can you make it public?

There is no need for npm install as part of the command. Netlify automatically installs packages listed in the package.json.

I have trun this repository to public, may you check again?

And I already have try command without npm install, but failed also.

I have (sort of) got it working locally using Netlify CLI (sort of because I don’t have the required credentials.)

These are the changes I made:

  • Remove the build script from package.json
  • Remove the command from netlify.toml
  • Change functions = "functions" to functions = "express" in netlify.toml

Then I ran netlify dev --offline and was able to load the function (which displayed hello world) in a browser.

Try making the above changes, and ensure the build command in the Netlify Dashboard is also blank. I suggest also making a directory called site with a blank index.html and setting this as the publish directory.

1 Like

Thank you very much for help!

This works fine now!