Build fails in yarn workspace: error TS2307: Cannot find module ** or its corresponding type declarations

During build with netlify, the module cannot be resolved, resulting in an error.
Checking the error log, it seems to be failing to resolve the dependency of the child package in the yarn workspace.

7:13:02 AM: ➤ YN0000: │ next-expo-solito-monorepo@workspace:. STDOUT ➤ YN0000: Command failed with exit code 2: npx tsc --baseUrl . --outDir types --rootDir src --emitDeclarationOnly --declarationMap (https://ntl.fyi/exit-code-2)
7:13:02 AM: ➤ YN0000: │ next-expo-solito-monorepo@workspace:. STDOUT ➤ YN0000: src/components/GameDetailsSheet.tsx(1,54): error TS2307: Cannot find module '@my/ui' or its corresponding type declarations.

Only in the netlify environment does it fail. For example, the build succeeds if I write the following in docker.
Is there any way to deal with this?

FROM node:16 

COPY . /app
WORKDIR /app

RUN yarn && yarn web:prod

EXPOSE 8151
ENTRYPOINT [ "yarn", "web:prod:serve" ]

– info –
build settings

site name: earnest-meringue-521103
repo: GitHub - ymuichiro/symbol-universal-wallet
build log:

7:13:03 AM: Failed during stage 'Install dependencies': dependency_installation script returned non-zero exit code: 1
7:11:17 AM: build-image version: ad28fb91fae632ef7f2e4d659a892d68ee2681a6 (focal)
7:11:17 AM: buildbot version: 751c8de2ba48c52549712392ca0244c53d39c3c1
7:11:17 AM: Building without cache
7:11:17 AM: Starting to prepare the repo for build
7:11:18 AM: No cached dependencies found. Cloning fresh repo
7:11:18 AM: git clone --filter=blob:none https://github.com/ymuichiro/symbol-universal-wallet
7:11:18 AM: Preparing Git Reference refs/heads/main
7:11:20 AM: Starting to install dependencies
7:11:20 AM: Python version set to 3.8
7:11:20 AM: Attempting Ruby version 2.7.2, read from environment
7:11:20 AM: Using Ruby version 2.7.2
7:11:21 AM: Started restoring cached go cache
7:11:21 AM: Finished restoring cached go cache
7:11:21 AM: go version go1.19.11 linux/amd64
7:11:21 AM: Using PHP version 8.0
7:11:22 AM: Downloading and installing node v16.17.0...
7:11:22 AM: Downloading https://nodejs.org/dist/v16.17.0/node-v16.17.0-linux-x64.tar.xz...
7:11:23 AM: Computing checksum with sha256sum
7:11:23 AM: Checksums matched!
7:11:24 AM: Now using node v16.17.0 (npm v8.15.0)
7:11:24 AM: Enabling Node.js Corepack
7:11:25 AM: Started restoring cached build plugins
7:11:25 AM: Finished restoring cached build plugins
7:11:25 AM: Started restoring cached corepack dependencies
7:11:25 AM: Finished restoring cached corepack dependencies
7:11:25 AM: Started restoring cached yarn cache
7:11:25 AM: Finished restoring cached yarn cache
7:11:25 AM: yarn workspaces detected
7:11:26 AM: Installing npm packages using Yarn version 3.5.0
7:11:26 AM: ➤ YN0000: ┌ Project validation
7:11:26 AM: ➤ YN0057: │ expo-app: Resolutions field will be ignored
7:11:26 AM: ➤ YN0000: └ Completed
7:11:26 AM: ➤ YN0000: ┌ Resolution step
7:11:27 AM: ➤ YN0000: └ Completed in 0s 329ms
7:11:27 AM: ➤ YN0000: ┌ Fetch step
7:12:13 AM: ➤ YN0066: │ typescript@patch:typescript@npm%3A5.1.6#~builtin<compat/typescript>::version=5.1.6&hash=85af82: Cannot apply hunk #1
7:12:33 AM: ➤ YN0000: └ Completed in 1m 6s
7:12:33 AM: ➤ YN0000: ┌ Link step
7:12:46 AM: ➤ YN0007: │ sharp@npm:0.32.4 must be built because it never has been before or the last one failed
7:12:46 AM: ➤ YN0007: │ turbo@npm:1.10.9 must be built because it never has been before or the last one failed
7:12:46 AM: ➤ YN0007: │ esbuild@npm:0.14.47 must be built because it never has been before or the last one failed
7:12:46 AM: ➤ YN0007: │ esbuild@npm:0.17.19 must be built because it never has been before or the last one failed
7:12:46 AM: ➤ YN0007: │ @nestjs/core@npm:9.3.11 [00126] must be built because it never has been before or the last one failed
7:12:46 AM: ➤ YN0007: │ esbuild@npm:0.17.6 must be built because it never has been before or the last one failed
7:12:46 AM: ➤ YN0007: │ esbuild@npm:0.18.15 must be built because it never has been before or the last one failed
7:12:46 AM: ➤ YN0007: │ deasync@npm:0.1.28 must be built because it never has been before or the last one failed
7:12:47 AM: ➤ YN0000: │ deasync@npm:0.1.28 STDOUT `linux-x64-node-16` exists; testing
7:12:47 AM: ➤ YN0000: │ deasync@npm:0.1.28 STDOUT Binary is fine; exiting
7:12:49 AM: ➤ YN0000: │ sharp@npm:0.32.4 STDOUT sharp: Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.14.3/libvips-8.14.3-linux-x64.tar.br
7:12:49 AM: ➤ YN0000: │ sharp@npm:0.32.4 STDOUT sharp: Integrity check passed for linux-x64
7:12:50 AM: ➤ YN0007: │ next-expo-solito-monorepo@workspace:. must be built because it never has been before or the last one failed
7:12:50 AM: ➤ YN0007: │ @openapitools/openapi-generator-cli@npm:2.7.0 must be built because it never has been before or the last one failed
7:13:02 AM: ➤ YN0000: │ next-expo-solito-monorepo@workspace:. STDOUT ➤ YN0000: Command failed with exit code 2: npx tsc --baseUrl . --outDir types --rootDir src --emitDeclarationOnly --declarationMap (https://ntl.fyi/exit-code-2)
7:13:02 AM: ➤ YN0000: │ next-expo-solito-monorepo@workspace:. STDOUT ➤ YN0000: src/components/GameDetailsSheet.tsx(1,54): error TS2307: Cannot find module '@my/ui' or its corresponding type declarations.
7:13:02 AM: ➤ YN0000: │ next-expo-solito-monorepo@workspace:. STDOUT ➤ YN0000: src/tabs/GameTab.tsx(1,87): error TS2307: Cannot find module '@my/ui' or its corresponding type declarations.
7:13:02 AM: ➤ YN0000: │ next-expo-solito-monorepo@workspace:. STDOUT ➤ YN0000: src/tabs/HistoryTab.tsx(1,68): error TS2307: Cannot find module '@my/ui' or its corresponding type declarations.
7:13:02 AM: ➤ YN0000: │ next-expo-solito-monorepo@workspace:. STDOUT ➤ YN0000: src/tabs/WalletTab.tsx(1,24): error TS2307: Cannot find module '@my/ui' or its corresponding type declarations.
7:13:02 AM: ➤ YN0000: │ next-expo-solito-monorepo@workspace:. STDOUT ➤ YN0000: Done in 9s 656ms
7:13:02 AM: ➤ YN0009: │ next-expo-solito-monorepo@workspace:. couldn't be built successfully (exit code 1, logs can be found here: /tmp/xfs-9cb93872/build.log)
➤ YN0000: └ Completed in 29s 515ms
7:13:02 AM: ➤ YN0000: Failed with errors in 1m 37s
7:13:03 AM: Error during Yarn install
7:13:03 AM: Build was terminated: dependency_installation script returned non-zero exit code: 1
7:13:03 AM: Failing build: Failed to install dependencies

Hi @ymuichiro,

I do not know the answer to this, so I have asked the devs to take a look.

1 Like

Thank you very much! By the way, can Netlify use yarn workspace? I’m assuming it’s an environment-dependent issue, since it’s not a problem in the docker container.

The version of yarn is 3.5 in the netlify environment variable.

Netlify can use Yarn workspaces. The devs has made some progress with your issue, but haven’t reached a conclusion yet. Once we have that info, we’ll let you know.

1 Like

Thank you! I will try to do some more carving out on my end.

Hi @ymuichiro,

The devs tried to check this and try to get this working locally, but that did not work with the current setup. They have created a branch: lukasholzer/symbol-universal-wallet (github.com) that should fix the issues. You need to just rely on the linking of yarn workspaces but for that to work properly, you need to get all deps right. After that, you should use turborepo for execution and building of its dependent target which you have installed and setup in their repo.

These are the build settings that got this working:

The deploy is here: Netlify App

1 Like

Thank you very much! I appreciate it very much!
We have reflected this in our code and it works fine.

Now that this has been resolved, we would like to continue development.