Skip to content

[Bug]: serverless function using "sharp" cannot find "sharp" module #1195

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

Closed
1 of 2 tasks
dbmikus opened this issue Feb 5, 2022 · 6 comments
Closed
1 of 2 tasks

[Bug]: serverless function using "sharp" cannot find "sharp" module #1195

dbmikus opened this issue Feb 5, 2022 · 6 comments
Labels
priority: low type: bug code to address defects in shipped code

Comments

@dbmikus
Copy link

dbmikus commented Feb 5, 2022

Summary

If you include "sharp" as a dependency in your package.json in a Next.js serverless function, it will not be bundled into your deployed functions and you will get an error:

Error: Cannot find module 'sharp'

I believe this is because of the DEFAULT_EXCLUDED_MODULES declaration in src/helpers/config.ts.

Steps to reproduce

I ran this on Typescript, but I assume the same problem holds for Javascript repos. Note, I am also using Yarn as a multi-package monorepo, if it's relevant. sharp is installed in one of the subpackages, not at the monorepo root.

npm install sharp

Make a file in src/pages/api/myfail.ts:

import sharp from 'sharp';

export default function () {
   ...
}

A link to a reproduction repository

No response

Plugin version

4.2.4

More information about your build

  • I am building using the CLI
  • I am building using file-based configuration (netlify.toml)

What OS are you using?

Linux

Your netlify.toml file

`netlify.toml`
[build]
# postinstall package.json scripts don't run when the dependency is cached, so
# we need to manually call those commands when we build in Netlify.
command = "yarn hardhat:compile && yarn components:build && yarn pixel:build && yarn frontend:build"
publish = "packages/frontend/.next"

[build.environment]
# Do not use this mnemonic for anything real. This is a shared mnemonic used by
# Hardhat.
MNEMONIC = "test test test test test test test test test test test junk"
NEXT_PUBLIC_APP_URL_SCHEME = "https"
NEXT_PUBLIC_APP_HOST = "app.supercool.xyz"

[[plugins]]
package = "@netlify/plugin-nextjs"

[functions]
node_bundler = "esbuild"
external_node_modules = ["sharp"]

# staging branch
[context.staging]
[context.staging.environment]
NEXT_PUBLIC_SHOW_CONNECTED_ADDRESS = "false"

# dev branch
[context.dev]
[context.dev.environment]
NEXT_PUBLIC_SHOW_CONNECTED_ADDRESS = "true"

Your public/_redirects file

`_redirects`
# Paste content of your `_redirects` file here

Your next.config.js file

`next.config.js`
# Paste content of your `next.config.js` file here. Check there is no private info in there.

Builds logs (or link to your logs)

Build logs
6:31:07 PM: Build ready to start
6:31:11 PM: build-image version: 122b31996ccaffd45d820a452d6227f8312110cc (focal)
6:31:11 PM: build-image tag: v4.5.3
6:31:11 PM: buildbot version: 0854df8549ceb2ae5c3f0bb7326040a5c2ced0c5
6:31:11 PM: Fetching cached dependencies
6:31:11 PM: Starting to download cache of 1.0GB
6:31:16 PM: Finished downloading cache in 4.795906935s
6:31:16 PM: Starting to extract cache
6:31:54 PM: Finished extracting cache in 38.56656924s
6:31:54 PM: Finished fetching cache in 43.556708242s
6:31:54 PM: Starting to prepare the repo for build
6:31:55 PM: Preparing Git Reference refs/heads/beta
6:31:56 PM: Parsing package.json dependencies
6:31:58 PM: Starting build script
6:31:58 PM: Installing dependencies
6:31:58 PM: Python version set to 2.7
6:31:58 PM: Started restoring cached node version
6:32:00 PM: Finished restoring cached node version
6:32:01 PM: v16.13.2 is already installed.
6:32:01 PM: Now using node v16.13.2 (npm v8.1.2)
6:32:01 PM: Started restoring cached build plugins
6:32:01 PM: Finished restoring cached build plugins
6:32:01 PM: Attempting ruby version 2.7.2, read from environment
6:32:03 PM: Using ruby version 2.7.2
6:32:03 PM: Using PHP version 8.0
6:32:03 PM: Started restoring cached yarn cache
6:32:19 PM: Finished restoring cached yarn cache
6:32:19 PM: Yarn workspaces detected
6:32:19 PM: Started restoring workspace packages/frontend node modules
6:32:19 PM: Finished restoring workspace packages/frontend node modules
6:32:19 PM: Started restoring workspace packages/hardhat node modules
6:32:19 PM: Finished restoring workspace packages/hardhat node modules
6:32:19 PM: Started restoring workspace packages/pixel-art-react node modules
6:32:19 PM: Finished restoring workspace packages/pixel-art-react node modules
6:32:19 PM: Started restoring workspace packages/ui-components node modules
6:32:19 PM: Finished restoring workspace packages/ui-components node modules
6:32:19 PM: Started restoring workspace root node modules
6:32:19 PM: Finished restoring workspace root node modules
6:32:20 PM: Installing NPM modules using Yarn version 1.22.10
6:32:20 PM: yarn install v1.22.10
6:32:20 PM: [1/4] Resolving packages...
6:32:22 PM: [2/4] Fetching packages...
6:32:24 PM: info @next/[email protected]: The platform "linux" is incompatible with this module.
6:32:24 PM: info "@next/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:32:24 PM: info @next/[email protected]: The CPU architecture "x64" is incompatible with this module.
6:32:24 PM: info @next/[email protected]: The platform "linux" is incompatible with this module.
6:32:24 PM: info "@next/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:32:24 PM: info @next/[email protected]: The CPU architecture "x64" is incompatible with this module.
6:32:24 PM: info @next/[email protected]: The platform "linux" is incompatible with this module.
6:32:24 PM: info "@next/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:32:24 PM: info @next/[email protected]: The CPU architecture "x64" is incompatible with this module.
6:32:24 PM: info "@next/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:32:24 PM: info @next/[email protected]: The CPU architecture "x64" is incompatible with this module.
6:32:24 PM: info "@next/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:32:24 PM: info @next/[email protected]: The CPU architecture "x64" is incompatible with this module.
6:32:24 PM: info "@next/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:32:24 PM: info @next/[email protected]: The platform "linux" is incompatible with this module.
6:32:24 PM: info "@next/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:32:24 PM: info @next/[email protected]: The CPU architecture "x64" is incompatible with this module.
6:32:24 PM: info @next/[email protected]: The platform "linux" is incompatible with this module.
6:32:24 PM: info "@next/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:32:24 PM: info @next/[email protected]: The CPU architecture "x64" is incompatible with this module.
6:32:24 PM: info @next/[email protected]: The platform "linux" is incompatible with this module.
6:32:24 PM: info "@next/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:32:24 PM: info @next/[email protected]: The platform "linux" is incompatible with this module.
6:32:24 PM: info "@next/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:32:24 PM: info @next/[email protected]: The CPU architecture "x64" is incompatible with this module.
6:32:24 PM: info @next/[email protected]: The platform "linux" is incompatible with this module.
6:32:24 PM: info "@next/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:32:24 PM: info @next/[email protected]: The platform "linux" is incompatible with this module.
6:32:24 PM: info "@next/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:32:24 PM: info [email protected]: The platform "linux" is incompatible with this module.
6:32:24 PM: info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:32:24 PM: info [email protected]: The platform "linux" is incompatible with this module.
6:32:24 PM: info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:32:24 PM: info [email protected]: The platform "linux" is incompatible with this module.
6:32:24 PM: info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:32:24 PM: [3/4] Linking dependencies...
6:32:24 PM: warning " > [email protected]" has unmet peer dependency "prettier@>=2.0.0".
6:32:24 PM: warning " > @pixly/[email protected]" has unmet peer dependency "react@^17.0.2 || ^16.0.0".
6:32:24 PM: warning " > @pixly/[email protected]" has unmet peer dependency "react-dom@^17.0.2 || ^16.0.0".
6:32:24 PM: warning " > @pixly/[email protected]" has unmet peer dependency "@types/styled-components@>= 5".
6:32:24 PM: warning " > @pixly/[email protected]" has unmet peer dependency "@types/styled-theming@>= 2".
6:32:24 PM: warning " > @pixly/[email protected]" has unmet peer dependency "styled-components@>= 5".
6:32:24 PM: warning " > @pixly/[email protected]" has unmet peer dependency "styled-theming@>= 2".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/frontend > @chakra-ui/[email protected]" has unmet peer dependency "@chakra-ui/system@>=1.0.0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/frontend > [email protected]" has unmet peer dependency "react-is@>= 16.8.0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/frontend > [email protected]" has unmet peer dependency "@babel/core@^7.0.0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/hardhat > @typechain/[email protected]" has unmet peer dependency "@ethersproject/bytes@^5.0.0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/hardhat > @typechain/[email protected]" has unmet peer dependency "@ethersproject/providers@^5.0.0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/hardhat > @typechain/[email protected]" has unmet peer dependency "@ethersproject/abi@^5.0.0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/hardhat > @typechain/[email protected]" has unmet peer dependency "lodash@^4.17.15".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/pixel-art-react > [email protected]" has unmet peer dependency "react@^16.8.5".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/pixel-art-react > [email protected]" has unmet peer dependency "react-dom@^16.8.5".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/pixel-art-react > [email protected]" has unmet peer dependency "react@*".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/pixel-art-react > [email protected]" has unmet peer dependency "react@^16.13.1".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/pixel-art-react > [email protected]" has unmet peer dependency "react@^0.14.0 || ^15.0.0 || ^16.0.0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/pixel-art-react > [email protected]" has unmet peer dependency "react-dom@^0.14.0 || ^15.0.0 || ^16.0.0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/pixel-art-react > [email protected]" has unmet peer dependency "react@^0.14.0 || ^15.0.0 || ^16 || ^17".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/pixel-art-react > [email protected]" has unmet peer dependency "react-dom@^0.14.0 || ^15.0.0 || ^16 || ^17".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/pixel-art-react > [email protected]" has unmet peer dependency "react@^16.8.3 || ^17".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/pixel-art-react > [email protected]" has unmet peer dependency "react@>=15.0.0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/pixel-art-react > [email protected]" has unmet peer dependency "react-dom@>=15.0.0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/ui-components > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/frontend > @chakra-ui/icons > @chakra-ui/[email protected]" has unmet peer dependency "@chakra-ui/system@>=1.0.0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/frontend > @emotion/styled > @emotion/[email protected]" has unmet peer dependency "@babel/core@^7.0.0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/frontend > babel-jest > [email protected]" has unmet peer dependency "@babel/core@^7.0.0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/pixel-art-react > react-beautiful-dnd > [email protected]" has unmet peer dependency "react@^16.8.0 || ^17.0.0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/pixel-art-react > react-color > @icons/[email protected]" has unmet peer dependency "react@*".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/ui-components > @babel/preset-typescript > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/frontend > @emotion/styled > @emotion/babel-plugin > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/frontend > babel-jest > babel-preset-jest > [email protected]" has unmet peer dependency "@babel/core@^7.0.0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/ui-components > next > styled-jsx > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/ui-components > @babel/preset-typescript > @babel/plugin-transform-typescript > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/frontend > babel-jest > babel-preset-jest > babel-preset-current-node-syntax > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
6:32:24 PM: warning "workspace-aggregator-a54b629a-142b-42aa-a7b0-f24dfe161ad6 > @pixly/frontend > babel-jest > babel-preset-jest > babel-preset-current-node-syntax > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
6:32:42 PM: [4/4] Building fresh packages...
6:33:05 PM: Done in 44.53s.
6:33:05 PM: NPM modules installed using Yarn
6:33:05 PM: Started restoring cached go cache
6:33:05 PM: Finished restoring cached go cache
6:33:05 PM: go version go1.16.5 linux/amd64
6:33:05 PM: go version go1.16.5 linux/amd64
6:33:05 PM: Installing missing commands
6:33:05 PM: Verify run directory
6:33:07 PM: ​
6:33:07 PM: ────────────────────────────────────────────────────────────────
6:33:07 PM:   Netlify Build                                                 
6:33:07 PM: ────────────────────────────────────────────────────────────────
6:33:07 PM: ​
6:33:07 PM: ❯ Version
6:33:07 PM:   @netlify/build 26.2.3
6:33:07 PM: ​
6:33:07 PM: ❯ Flags
6:33:07 PM:   baseRelDir: true
6:33:07 PM:   buildId: 61fde16b24b9c40007750f08
6:33:07 PM:   deployId: 61fde16b24b9c40007750f0a
6:33:07 PM: ​
6:33:07 PM: ❯ Current directory
6:33:07 PM:   /opt/build/repo
6:33:07 PM: ​
6:33:07 PM: ❯ Config file
6:33:07 PM:   /opt/build/repo/netlify.toml
6:33:07 PM: ​
6:33:07 PM: ❯ Context
6:33:07 PM:   production
6:33:07 PM: ​
6:33:07 PM: ❯ Loading plugins
6:33:07 PM:    - @netlify/[email protected] from netlify.toml and package.json
6:33:09 PM: ​
6:33:09 PM: ────────────────────────────────────────────────────────────────
6:33:09 PM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
6:33:09 PM: ────────────────────────────────────────────────────────────────
6:33:09 PM: ​
6:33:10 PM: Next.js cache restored.
6:33:10 PM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
6:33:10 PM: ​
6:33:10 PM: (@netlify/plugin-nextjs onPreBuild completed in 651ms)
6:33:10 PM: ​
6:33:10 PM: ────────────────────────────────────────────────────────────────
6:33:10 PM:   2. build.command from netlify.toml                            
6:33:10 PM: ────────────────────────────────────────────────────────────────
6:33:10 PM: ​
6:33:10 PM: $ yarn hardhat:compile && yarn components:build && yarn pixel:build && yarn frontend:build
6:33:10 PM: yarn run v1.22.10
6:33:10 PM: $ yarn workspace @pixly/hardhat compile
6:33:11 PM: $ npx hardhat compile
6:33:19 PM: Solidity 0.8.11 is not fully supported yet. You can still use Hardhat, but some features, like stack traces, might not work correctly.
6:33:19 PM: 
6:33:19 PM: Learn more at https://hardhat.org/reference/solidity-support
6:33:19 PM: 
6:33:22 PM: Downloading compiler 0.8.11
6:33:23 PM: Compiling 28 files with 0.8.11
6:33:28 PM: Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
6:33:28 PM:   --> contracts/RleRendererV3.sol:10:5:
6:33:28 PM:    |
6:33:28 PM: 10 |     constructor () public {
6:33:28 PM:    |     ^ (Relevant source part starts here and spans across multiple lines).
6:33:28 PM: 
6:33:28 PM: 
6:33:28 PM: Warning: Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable.
6:33:28 PM:   --> contracts/Frames.sol:14:13:
6:33:28 PM:    |
6:33:28 PM: 14 |             string memory,
6:33:28 PM:    |             ^^^^^^^^^^^^^
6:33:28 PM: 
6:33:28 PM: 
6:33:28 PM: Warning: Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable.
6:33:28 PM:   --> contracts/Frames.sol:15:13:
6:33:28 PM:    |
6:33:28 PM: 15 |             uint256,
6:33:28 PM:    |             ^^^^^^^
6:33:28 PM: 
6:33:28 PM: 
6:33:28 PM: Warning: Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable.
6:33:28 PM:   --> contracts/Frames.sol:16:13:
6:33:28 PM:    |
6:33:28 PM: 16 |             string[] memory
6:33:28 PM:    |             ^^^^^^^^^^^^^^^
6:33:28 PM: 
6:33:28 PM: 
6:33:28 PM: Warning: Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable.
6:33:28 PM:    --> contracts/Frames.sol:148:30:
6:33:28 PM:     |
6:33:28 PM: 148 |     ) internal pure returns (uint256) {
6:33:28 PM:     |                              ^^^^^^^
6:33:28 PM: 
6:33:28 PM: 
6:33:29 PM: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org/ for more information.
6:33:29 PM: --> contracts/Multicall.sol
6:33:29 PM: 
6:33:29 PM: 
6:33:29 PM: Generating typings for: 28 artifacts in dir: ../frontend/types/typechain for target: ethers-v5
6:33:32 PM: Successfully generated 45 typings!
6:33:32 PM: Compilation finished successfully
6:33:32 PM: Done in 21.83s.
6:33:32 PM: yarn run v1.22.10
6:33:32 PM: $ yarn workspace @pixly/ui-components build
6:33:33 PM: warning package.json: No license field
6:33:33 PM: $ tsc --build
6:33:33 PM: Done in 1.09s.
6:33:34 PM: yarn run v1.22.10
6:33:34 PM: $ yarn workspace @pixly/pixel-art-react build
6:33:34 PM: $ NODE_ENV=production webpack -p --config webpack.production.config.js
6:33:45 PM: Done in 11.24s.
6:33:45 PM: yarn run v1.22.10
6:33:45 PM: $ yarn workspace @pixly/frontend build
6:33:46 PM: warning package.json: "dependencies" has dependency "eslint-config-next" with range "^12.0.0" that collides with a dependency in "devDependencies" of the same name with version "^11.0.1"
6:33:46 PM: $ next build
6:33:47 PM: info  - Checking validity of types...
6:34:00 PM: warn  - The Next.js plugin was not detected in your ESLint configuration. See https://nextjs.org/docs/basic-features/eslint#migrating-existing-config
6:34:02 PM: info  - Creating an optimized production build...
6:34:02 PM: info  - Disabled SWC as replacement for Babel because of custom Babel configuration ".babelrc" https://nextjs.org/docs/messages/swc-disabled
6:34:14 PM: info  - Compiled successfully
6:34:14 PM: info  - Collecting page data...
6:34:20 PM: info  - Generating static pages (0/5)
6:34:20 PM: Handling InitPixlyContract action
6:34:20 PM: Working on Chain Id 0
6:34:20 PM: Handling InitPixlyContract action
6:34:20 PM: Working on Chain Id 0
6:34:20 PM: Handling InitPixlyContract action
6:34:20 PM: Working on Chain Id 0
6:34:20 PM: info  - Generating static pages (1/5)
6:34:20 PM: Handling InitPixlyContract action
6:34:20 PM: Working on Chain Id 0
6:34:20 PM: info  - Generating static pages (2/5)
6:34:20 PM: info  - Generating static pages (3/5)
6:34:21 PM: Handling InitPixlyContract action
6:34:21 PM: Working on Chain Id 0
6:34:22 PM: info  - Generating static pages (5/5)
6:34:22 PM: info  - Finalizing page optimization...
6:34:22 PM: Page                                       Size     First Load JS
6:34:22 PM: ┌ ○ / (622 ms)                             200 kB          649 kB
6:34:22 PM: ├   /_app                                  0 B             350 kB
6:34:22 PM: ├ ○ /404                                   2.83 kB         353 kB
6:34:22 PM: ├ λ /api/pixlies/[tokenId]/png             0 B             350 kB
6:34:22 PM: ├ λ /api/pixlies/[tokenId]/svg             0 B             350 kB
6:34:22 PM: ├ λ /pixlies/[tokenId]                     3.6 kB          460 kB
6:34:22 PM: ├ ○ /pixlies/all (569 ms)                  3.42 kB         459 kB
6:34:22 PM: └ ○ /pixlies/mine (1439 ms)                3.5 kB          460 kB
6:34:22 PM: + First Load JS shared by all              350 kB
6:34:22 PM:   ├ chunks/framework-c4190dd27fdc6a34.js   42 kB
6:34:22 PM:   ├ chunks/main-874141b7e85a48b9.js        24.9 kB
6:34:22 PM:   ├ chunks/pages/_app-906f1ec516fff170.js  282 kB
6:34:22 PM:   ├ chunks/webpack-252addb9facfd8f2.js     1.64 kB
6:34:22 PM:   └ css/8858bcab60a142c5.css               23.8 kB
6:34:22 PM: λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
6:34:22 PM: ○  (Static)  automatically rendered as static HTML (uses no initial props)
6:34:22 PM: Done in 36.64s.
6:34:22 PM: ​
6:34:22 PM: (build.command completed in 1m 11.7s)
6:34:22 PM: ​
6:34:22 PM: ────────────────────────────────────────────────────────────────
6:34:22 PM:   3. @netlify/plugin-nextjs (onBuild event)                     
6:34:22 PM: ────────────────────────────────────────────────────────────────
6:34:22 PM: ​
6:34:22 PM: Patching /opt/build/repo/node_modules/next/dist/server/base-server.js
6:34:22 PM: Done
6:34:22 PM: Moving static page files to serve from CDN...
6:34:22 PM: Moved 3 files
6:34:22 PM: Netlify configuration property "redirects" value changed to [
6:34:22 PM:   { from: '/_next/static/*', to: '/static/:splat', status: 200 },
6:34:22 PM:   {
6:34:22 PM:     from: '/_next/image*',
6:34:22 PM:     query: { url: ':url', w: ':width', q: ':quality' },
6:34:22 PM:     to: '/_ipx/w_:width,q_:quality/:url',
6:34:22 PM:     status: 301
6:34:22 PM:   },
6:34:22 PM:   { from: '/_ipx/*', to: '/.netlify/builders/_ipx', status: 200 },
6:34:22 PM:   { from: '/cache/*', to: '/404.html', status: 404, force: true },
6:34:22 PM:   { from: '/server/*', to: '/404.html', status: 404, force: true },
6:34:22 PM:   { from: '/serverless/*', to: '/404.html', status: 404, force: true },
6:34:22 PM:   { from: '/traces', to: '/404.html', status: 404, force: true },
6:34:22 PM:   {
6:34:22 PM:     from: '/routes-manifest.json',
6:34:22 PM:     to: '/404.html',
6:34:22 PM:     status: 404,
6:34:22 PM:     force: true
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/build-manifest.json',
6:34:22 PM:     to: '/404.html',
6:34:22 PM:     status: 404,
6:34:22 PM:     force: true
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/prerender-manifest.json',
6:34:22 PM:     to: '/404.html',
6:34:22 PM:     status: 404,
6:34:22 PM:     force: true
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/react-loadable-manifest.json',
6:34:22 PM:     to: '/404.html',
6:34:22 PM:     status: 404,
6:34:22 PM:     force: true
6:34:22 PM:   },
6:34:22 PM:   { from: '/BUILD_ID', to: '/404.html', status: 404, force: true },
6:34:22 PM:   {
6:34:22 PM:     from: '/api',
6:34:22 PM:     to: '/.netlify/functions/___netlify-handler',
6:34:22 PM:     status: 200
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/api/*',
6:34:22 PM:     to: '/.netlify/functions/___netlify-handler',
6:34:22 PM:     status: 200
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/favicon.ico',
6:34:22 PM:     to: '/favicon.ico',
6:34:22 PM:     conditions: { Cookie: [Array] },
6:34:22 PM:     status: 200
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/images/Logos_Supercool_Final.svg',
6:34:22 PM:     to: '/images/Logos_Supercool_Final.svg',
6:34:22 PM:     conditions: { Cookie: [Array] },
6:34:22 PM:     status: 200
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/images/logo-metamask.png',
6:34:22 PM:     to: '/images/logo-metamask.png',
6:34:22 PM:     conditions: { Cookie: [Array] },
6:34:22 PM:     status: 200
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/images/logo-walletconnect.svg',
6:34:22 PM:     to: '/images/logo-walletconnect.svg',
6:34:22 PM:     conditions: { Cookie: [Array] },
6:34:22 PM:     status: 200
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/*',
6:34:22 PM:     to: '/.netlify/functions/___netlify-handler',
6:34:22 PM:     status: 200,
6:34:22 PM:     conditions: { Cookie: [Array] },
6:34:22 PM:     force: true
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/_next/data/Wfj-OneDG5A1VqO6bRnVw/index.json',
6:34:22 PM:     to: '/.netlify/functions/___netlify-handler',
6:34:22 PM:     status: 200,
6:34:22 PM:     force: false
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/',
6:34:22 PM:     to: '/.netlify/functions/___netlify-handler',
6:34:22 PM:     status: 200,
6:34:22 PM:     force: false
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/_next/data/Wfj-OneDG5A1VqO6bRnVw/pixlies/all.json',
6:34:22 PM:     to: '/.netlify/functions/___netlify-handler',
6:34:22 PM:     status: 200,
6:34:22 PM:     force: false
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/pixlies/all',
6:34:22 PM:     to: '/.netlify/functions/___netlify-handler',
6:34:22 PM:     status: 200,
6:34:22 PM:     force: false
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/_next/data/Wfj-OneDG5A1VqO6bRnVw/pixlies/mine.json',
6:34:22 PM:     to: '/.netlify/functions/___netlify-handler',
6:34:22 PM:     status: 200,
6:34:22 PM:     force: false
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/pixlies/mine',
6:34:22 PM:     to: '/.netlify/functions/___netlify-handler',
6:34:22 PM:     status: 200,
6:34:22 PM:     force: false
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/_next/data/Wfj-OneDG5A1VqO6bRnVw/pixlies/:tokenId.json',
6:34:22 PM:     to: '/.netlify/functions/___netlify-handler',
6:34:22 PM:     status: 200,
6:34:22 PM:     force: false
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/pixlies/:tokenId',
6:34:22 PM:     to: '/.netlify/functions/___netlify-handler',
6:34:22 PM:     status: 200,
6:34:22 PM:     force: false
6:34:22 PM:   },
6:34:22 PM:   {
6:34:22 PM:     from: '/*',
6:34:22 PM:     to: '/.netlify/functions/___netlify-handler',
6:34:22 PM:     status: 200
6:34:22 PM:   }
6:34:22 PM: ].
6:34:22 PM: ​
6:34:22 PM: (@netlify/plugin-nextjs onBuild completed in 108ms)
6:34:22 PM: ​
6:34:22 PM: ────────────────────────────────────────────────────────────────
6:34:22 PM:   4. Functions bundling                                         
6:34:22 PM: ────────────────────────────────────────────────────────────────
6:34:22 PM: ​
6:34:22 PM: Packaging Functions from .netlify/functions-internal directory:
6:34:22 PM:  - ___netlify-handler/___netlify-handler.js
6:34:22 PM:  - ___netlify-odb-handler/___netlify-odb-handler.js
6:34:22 PM:  - _ipx/_ipx.js
6:34:22 PM: ​
6:34:59 PM: ​
6:34:59 PM: (Functions bundling completed in 36.8s)
6:34:59 PM: ​
6:34:59 PM: ────────────────────────────────────────────────────────────────
6:34:59 PM:   5. @netlify/plugin-nextjs (onPostBuild event)                 
6:34:59 PM: ────────────────────────────────────────────────────────────────
6:34:59 PM: ​
6:34:59 PM: Next.js cache saved.
6:34:59 PM: ​
6:34:59 PM: (@netlify/plugin-nextjs onPostBuild completed in 362ms)
6:34:59 PM: ​
6:34:59 PM: ────────────────────────────────────────────────────────────────
6:34:59 PM:   6. Deploy site                                                
6:34:59 PM: ────────────────────────────────────────────────────────────────
6:34:59 PM: ​
6:34:59 PM: Starting to deploy site from 'packages/frontend/.next'
6:35:00 PM: Creating deploy tree 
6:35:00 PM: Creating deploy upload records
6:35:00 PM: 19 new files to upload
6:35:00 PM: 3 new functions to upload
6:35:09 PM: Site deploy was successfully initiated
6:35:09 PM: ​
6:35:09 PM: (Deploy site completed in 9.3s)
6:35:09 PM: ​
6:35:09 PM: ────────────────────────────────────────────────────────────────
6:35:09 PM:   Netlify Build Complete                                        
6:35:09 PM: ────────────────────────────────────────────────────────────────
6:35:09 PM: ​
6:35:09 PM: (Netlify Build completed in 2m 1.5s)
6:35:09 PM: Starting post processing
6:35:09 PM: Post processing - HTML
6:35:09 PM: Caching artifacts
6:35:09 PM: Started saving workspace packages/frontend node modules
6:35:09 PM: Finished saving workspace packages/frontend node modules
6:35:09 PM: Started saving workspace packages/hardhat node modules
6:35:09 PM: Finished saving workspace packages/hardhat node modules
6:35:09 PM: Started saving workspace packages/pixel-art-react node modules
6:35:09 PM: Finished saving workspace packages/pixel-art-react node modules
6:35:09 PM: Started saving workspace packages/ui-components node modules
6:35:09 PM: Finished saving workspace packages/ui-components node modules
6:35:09 PM: Started saving workspace root node modules
6:35:09 PM: Finished saving workspace root node modules
6:35:09 PM: Started saving build plugins
6:35:09 PM: Finished saving build plugins
6:35:09 PM: Started saving yarn cache
6:35:09 PM: Post processing - header rules
6:35:09 PM: Post processing - redirect rules
6:35:10 PM: Post processing done
6:35:11 PM: Site is live ✨
6:35:24 PM: Finished saving yarn cache
6:35:24 PM: Started saving pip cache
6:35:24 PM: Finished saving pip cache
6:35:24 PM: Started saving emacs cask dependencies
6:35:24 PM: Finished saving emacs cask dependencies
6:35:24 PM: Started saving maven dependencies
6:35:24 PM: Finished saving maven dependencies
6:35:24 PM: Started saving boot dependencies
6:35:25 PM: Finished saving boot dependencies
6:35:25 PM: Started saving rust rustup cache
6:35:25 PM: Finished saving rust rustup cache
6:35:25 PM: Started saving go dependencies
6:35:25 PM: Finished saving go dependencies
6:35:25 PM: Build script success
6:38:13 PM: Finished processing build request in 7m2.047346671s```

</details>


### Function logs

<details>
  <summary>Function logs</summary>
  

01:54:15 PM: c9f3c7a0 INFO [GET] /pixlies/17?chainId=80001 (SSR)
01:54:15 PM: c9f3c7a0 Duration: 41.14 ms Memory Usage: 145 MB 01:54:16 PM: 62255a1a ERROR Error: Cannot find module 'sharp'
Require stack:

  • /var/task/packages/frontend/.next/server/pages/api/pixlies/[tokenId]/png.js
  • /var/task/node_modules/next/dist/server/next-server.js
  • /var/task/.netlify/functions-internal/___netlify-handler/handlerUtils.js
  • /var/task/.netlify/functions-internal/___netlify-handler/___netlify-handler.js
  • /var/task/___netlify-handler.js
  • /var/runtime/UserFunction.js
  • /var/runtime/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Module.9359 (/var/task/packages/frontend/.next/server/pages/api/pixlies/[tokenId]/png.js:20:40)
    at webpack_require (/var/task/packages/frontend/.next/server/webpack-runtime.js:25:43)
    at webpack_exec (/var/task/packages/frontend/.next/server/pages/api/pixlies/[tokenId]/png.js:126:39)
    at /var/task/packages/frontend/.next/server/pages/api/pixlies/[tokenId]/png.js:127:78
    at Function.webpack_require.X (/var/task/packages/frontend/.next/server/webpack-runtime.js:108:21)
    at /var/task/packages/frontend/.next/server/pages/api/pixlies/[tokenId]/png.js:127:47 {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    '/var/task/packages/frontend/.next/server/pages/api/pixlies/[tokenId]/png.js',
    '/var/task/node_modules/next/dist/server/next-server.js',
    '/var/task/.netlify/functions-internal/___netlify-handler/handlerUtils.js',
    '/var/task/.netlify/functions-internal/___netlify-handler/___netlify-handler.js',
    '/var/task/___netlify-handler.js',
    '/var/runtime/UserFunction.js',
    '/var/runtime/index.js'
    ]
    }

</details>


### .next JSON files

<details>
  <summary>generated .next JSON files</summary>
  

Paste file contents here. Please check there isn't any private info in them

You can either build locally, or download the deploy from Netlify by clicking the arrow next to the deploy time.


</details>
@dbmikus dbmikus added the type: bug code to address defects in shipped code label Feb 5, 2022
@dbmikus
Copy link
Author

dbmikus commented Feb 5, 2022

I was able to fix my issue by using yarn package aliases, like

yarn workspace @pixly/frontend add mysharp@npm:sharp

and then importing mysharp instead of sharp.

@kurpav
Copy link

kurpav commented Feb 17, 2022

are there any better ideas on how to fix it?

@benjamindell
Copy link

I'm also facing this issue. Are there any solutions other than creating an npm / yarn alias?

@Fox32
Copy link

Fox32 commented Jun 23, 2022

So the issue is that sharp is excluded from the bundle to keep the size reasonable. For our project we created a custom netlify build plugin that removes the exclusion.

What we did:

  1. We have a plugin folder include_sharp/ in our project with a package.json:
{
  "name": "include_sharp",
  "version": "1.0.0",
  "main": "index.js"
}
  1. We have a plugin manifest manifest.yml:
name: include_sharp
  1. And the plugin code itself in the index.js:
module.exports = {
  async onBuild({ netlifyConfig }) {
    const fn = netlifyConfig.functions['___netlify-handler'];

    fn.included_files = fn.included_files.filter(
      (f) => f !== '!node_modules/sharp/**/*'
    );
  },
};
  1. In the end we reference the plugin in our netlify.toml, after the netlify-plugin-nextjs plugin:
[[plugins]]
  package = "@netlify/plugin-nextjs"

[[plugins]]
  package = "./include_sharp"

This way the sharp module is not excluded from the bundle anymore. This is kind of a hack, but works without additional external packages.

@solace
Copy link

solace commented Oct 24, 2022

I was able to fix my issue by using yarn package aliases, like

yarn workspace @pixly/frontend add mysharp@npm:sharp

Save
and then importing mysharp instead of sharp.

I tried a variety of things including the include_sharp suggestion above, but setting a package alias was the only thing that worked for me. Thank you.

@sarahetter
Copy link

#1745
This issue has been solved here. To include sharp, add it to included_files in your netlify.toml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

6 participants