@netlify/plugin-functions-core fails on dependencies that are bundled already


In my build process I am doing this:

1:51:24 PM: Build ready to start
1:51:28 PM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6
1:51:28 PM: build-image tag: v3.4.1
1:51:28 PM: buildbot version: 8c957a6d09a03023cea4239847cc73a9cb64eeb7
1:51:28 PM: Fetching cached dependencies
1:51:29 PM: Starting to download cache of 90.2MB
1:51:30 PM: Finished downloading cache in 1.436499642s
1:51:30 PM: Starting to extract cache
1:51:33 PM: Finished extracting cache in 3.332542802s
1:51:33 PM: Finished fetching cache in 4.798891319s
1:51:33 PM: Starting to prepare the repo for build
1:51:34 PM: Preparing Git Reference refs/heads/crypto-app
1:51:35 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'target/dist' versus 'target' in the Netlify UI
1:51:35 PM: Starting build script
1:51:35 PM: Installing dependencies
1:51:35 PM: Python version set to 2.7
1:51:36 PM: Started restoring cached node version
1:51:39 PM: Finished restoring cached node version
1:51:40 PM: v12.18.0 is already installed.
1:51:40 PM: Now using node v12.18.0 (npm v6.14.4)
1:51:40 PM: Started restoring cached build plugins
1:51:40 PM: Finished restoring cached build plugins
1:51:41 PM: Attempting ruby version 2.7.1, read from environment
1:51:42 PM: Using ruby version 2.7.1
1:51:42 PM: Using PHP version 5.6
1:51:42 PM: 5.2 is already installed.
1:51:43 PM: Using Swift version 5.2
1:51:43 PM: Started restoring cached node modules
1:51:43 PM: Finished restoring cached node modules
1:51:43 PM: Installing NPM modules using NPM version 6.14.4
1:52:29 PM: > deasync@0.1.20 install /opt/build/repo/node_modules/deasync
1:52:29 PM: > node ./build.js
1:52:29 PM: `linux-x64-node-12` exists; testing
1:52:29 PM: Binary is fine; exiting
1:52:29 PM: > husky@4.3.0 install /opt/build/repo/node_modules/husky
1:52:29 PM: > node husky install
1:52:29 PM: husky > Setting up git hooks
1:52:29 PM: CI detected, skipping Git hooks installation.
1:52:29 PM: husky > Done
1:52:31 PM: > husky@4.3.0 postinstall /opt/build/repo/node_modules/husky
1:52:31 PM: > opencollective-postinstall || exit 0
1:52:31 PM: > netlify-cli@2.63.2 postinstall /opt/build/repo/node_modules/netlify-cli
1:52:31 PM: > node ./scripts/postinstall.js
1:52:31 PM: Success! Netlify CLI has been installed!
1:52:31 PM: Your device is now configured to use Netlify CLI to deploy and manage your Netlify sites.
1:52:31 PM: Next steps:
1:52:31 PM:   netlify init     Connect or create a Netlify site from current directory
1:52:31 PM:   netlify deploy   Deploy the latest changes to your Netlify site
1:52:31 PM: For more information on the CLI run netlify help
1:52:31 PM: Or visit the docs at https://cli.netlify.com
1:52:31 PM: > parcel-bundler@1.12.4 postinstall /opt/build/repo/node_modules/parcel-bundler
1:52:31 PM: > node -e "console.log('\u001b[35m\u001b[1mLove Parcel? You can now donate to our open collective:\u001b[22m\u001b[39m\n > \u001b[34mhttps://opencollective.com/parcel/donate\u001b[0m')"
1:52:31 PM: Love Parcel? You can now donate to our open collective:
1:52:31 PM:  > https://opencollective.com/parcel/donate
1:52:34 PM: npm WARN autoprefixer@10.0.0 requires a peer of postcss@^8.0.2 but none is installed. You must install peer dependencies yourself.
1:52:34 PM: npm WARN static-site-starter-kit@1.0.0 No repository field.
1:52:34 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/fsevents):
1:52:34 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
1:52:34 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/@parcel/watcher/node_modules/fsevents):
1:52:34 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
1:52:34 PM: added 2042 packages from 831 contributors, removed 3 packages, updated 15 packages and audited 2600 packages in 50.584s
1:52:36 PM: 92 packages are looking for funding
1:52:36 PM:   run `npm fund` for details
1:52:36 PM: found 0 vulnerabilities
1:52:37 PM: NPM modules installed
1:52:37 PM: Started restoring cached go cache
1:52:37 PM: Finished restoring cached go cache
1:52:37 PM: go version go1.14.4 linux/amd64
1:52:37 PM: go version go1.14.4 linux/amd64
1:52:37 PM: Installing missing commands
1:52:37 PM: Verify run directory
1:52:38 PM: ​
1:52:38 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
1:52:38 PM: β”‚        Netlify Build        β”‚
1:52:38 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
1:52:38 PM: ​
1:52:38 PM: ❯ Version
1:52:38 PM:   @netlify/build 3.3.5
1:52:38 PM: ​
1:52:38 PM: ❯ Flags
1:52:38 PM:   deployId: 5f649f3c33a6490008ca82f5
1:52:38 PM:   mode: buildbot
1:52:38 PM: ​
1:52:38 PM: ❯ Current directory
1:52:38 PM:   /opt/build/repo
1:52:38 PM: ​
1:52:38 PM: ❯ Config file
1:52:38 PM:   /opt/build/repo/netlify.toml
1:52:38 PM: ​
1:52:38 PM: ❯ Context
1:52:38 PM:   production
1:52:40 PM: ​
1:52:40 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
1:52:40 PM: β”‚ 1. build.command from netlify.toml β”‚
1:52:40 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
1:52:40 PM: ​
1:52:40 PM: $ npm run build
1:52:40 PM: > static-site-starter-kit@1.0.0 build /opt/build/repo
1:52:40 PM: > npm run build:css; npm run build:eleventy; npm run build:common; npm run build:parcel
1:52:40 PM: > static-site-starter-kit@1.0.0 build:css /opt/build/repo
1:52:40 PM: > ELEVENTY_PRODUCTION=true & NODE_ENV=production postcss styles/tailwind.css --o .tmp/style.css
1:52:41 PM: risk - There are upcoming breaking changes: removeDeprecatedGapUtilities, purgeLayersByDefault
1:52:41 PM: risk - We highly recommend opting-in to these changes now to simplify upgrading Tailwind in the future.
1:52:41 PM: risk - https://tailwindcss.com/docs/upcoming-changes
1:52:41 PM: warn - Tailwind is not purging unused styles because no template paths have been provided.
1:52:41 PM: warn - If you have manually configured PurgeCSS outside of Tailwind or are deliberately not removing unused styles, set `purge: false` in your Tailwind config file to silence this warning.
1:52:41 PM: warn - https://tailwindcss.com/docs/controlling-file-size/#removing-unused-css
1:52:44 PM: > static-site-starter-kit@1.0.0 build:eleventy /opt/build/repo
1:52:44 PM: > NODE_ENV=production eleventy
1:52:44 PM: Writing target/index.html from ./source/index.njk.
1:52:44 PM: Writing target/manifest.json from ./source/manifest.njk.
1:52:44 PM: Writing target/robots.txt from ./source/robots.njk.
1:52:44 PM: Writing target/sitemap.xml from ./source/sitemap.njk.
1:52:44 PM: Writing target/includes/navigation/index.html from ./source/includes/navigation.njk.
1:52:44 PM: Writing target/layouts/index.html from ./source/layouts/index.njk.
1:52:44 PM: Copied 1 file / Wrote 6 files in 0.27 seconds (v0.11.0)
1:52:44 PM: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
1:52:45 PM: > static-site-starter-kit@1.0.0 build:common /opt/build/repo
1:52:45 PM: > bin/common
1:52:45 PM: 09/18/20 11:52:45 AM Copy complete
1:52:45 PM: > static-site-starter-kit@1.0.0 build:parcel /opt/build/repo
1:52:45 PM: > NODE_ENV=production parcel build -t node -d target/functions source/functions/**/*.ts
1:52:49 PM: ✨  Built in 2.90s.
1:52:49 PM: target/functions/markets.js.map    12.82 KB      7ms
1:52:49 PM: target/functions/markets.js         6.64 KB    2.83s
1:52:49 PM: ​
1:52:49 PM: (build.command completed in 9.5s)
1:52:49 PM: ​
1:52:49 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
1:52:49 PM: β”‚ 2. onPostBuild command from @netlify/plugin-functions-core β”‚
1:52:49 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
1:52:49 PM: ​
1:52:49 PM: Packaging Functions from target/functions directory:
1:52:49 PM:  - markets.js
1:52:49 PM: ​
1:52:49 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
1:52:49 PM: β”‚ Plugin "@netlify/plugin-functions-core" internal error β”‚
1:52:49 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
1:52:49 PM: ​
1:52:49 PM:   Error message
1:52:49 PM:   Error: In file "/opt/build/repo/target/functions/markets.js": Cannot find module './common/binance' from '/opt/build/repo/target/functions'
1:52:49 PM: ​
1:52:49 PM:   Plugin details
1:52:49 PM:   Package:        @netlify/plugin-functions-core
1:52:49 PM:   Version:        3.3.5
1:52:49 PM:   Repository:     git+https://github.com/netlify/build.git
1:52:49 PM:   npm link:       https://www.npmjs.com/package/@netlify/build
1:52:49 PM:   Report issues:  https://github.com/netlify/build/issues
1:52:49 PM: ​
1:52:49 PM:   Error location
1:52:49 PM:   In "onPostBuild" event in "@netlify/plugin-functions-core" from core
1:52:49 PM:       at /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/resolve/lib/async.js:142:35
1:52:49 PM:       at load (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/resolve/lib/async.js:161:43)
1:52:49 PM:       at onex (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/resolve/lib/async.js:186:17)
1:52:49 PM:       at /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/resolve/lib/async.js:13:69
1:52:49 PM:       at FSReqCallback.oncomplete (fs.js:167:21)
1:52:49 PM: ​
1:52:49 PM:   Error properties
1:52:49 PM:   { code: 'MODULE_NOT_FOUND' }
1:52:49 PM: ​
1:52:49 PM:   Resolved config
1:52:49 PM:   build:
1:52:49 PM:     command: npm run build
1:52:49 PM:     commandOrigin: config
1:52:49 PM:     functions: /opt/build/repo/target/functions
1:52:49 PM:     publish: /opt/build/repo/target/dist
1:52:49 PM: Caching artifacts
1:52:49 PM: Started saving node modules
1:52:49 PM: Finished saving node modules
1:52:49 PM: Started saving build plugins
1:52:49 PM: Finished saving build plugins
1:52:49 PM: Started saving pip cache
1:52:50 PM: Finished saving pip cache
1:52:50 PM: Started saving emacs cask dependencies
1:52:50 PM: Finished saving emacs cask dependencies
1:52:50 PM: Started saving maven dependencies
1:52:50 PM: Finished saving maven dependencies
1:52:50 PM: Started saving boot dependencies
1:52:50 PM: Finished saving boot dependencies
1:52:50 PM: Started saving go dependencies
1:52:50 PM: Finished saving go dependencies
1:52:50 PM: Error running command: Build script returned non-zero exit code: 1
1:52:50 PM: Failing build: Failed to build site
1:52:50 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1
1:52:50 PM: Finished processing build request in 1m21.522673389s

This means that Parcel Bundler has created the markets.js file with all dependencies bundled in that file.

Somehow plugin-functions-core tries to read this compiled/output file and require the dependencies.

How do I get it to just take the file as is?

1 Like

This is the markets.js file.

As you can see, the dependencies (β€˜common/binance’) are bundled.

When I run it with node target/functions/markets.js then it runs without problems.

Hi @Industrial,

When Netlify bundles Functions, it tries to guess the dependencies tree by looking for any require() statement in the Functions files. We are currently lacking a way to exclude specific require() statements. There is a feature request describing this in details in https://github.com/netlify/zip-it-and-ship-it/issues/68.

In your case, the Parcel bundles includes the following line, so the algorithm assumes this file requires a sibling file ./common/binance. It does not understand that require() is an injected function, not the usual Node.js require(). This is a shortcoming from the current design of Netlify Functions bundling, which favors simplicity over edge cases like this one.

I have opened a feature request at https://github.com/netlify/zip-it-and-ship-it/issues/206 to better support Parcel.