vitejs / vite

Next generation frontend tooling. It's fast!
http://vite.dev
MIT License
68.58k stars 6.19k forks source link

Build fails with a failed to resolve "extends":"../../tsconfig.json" #6724

Closed iakovosvo closed 2 years ago

iakovosvo commented 2 years ago

Describe the bug

I am trying to build a new React (Typescript) app but I get this error:

[vite:esbuild] failed to resolve "extends":"../../tsconfig.json" in /Users/me/my-app/node_modules/@my-library/my-package/tsconfig.json

This comes from my organization's monorepo. Is there any way to solve this? I can see from the documentation that using extends can affect the build.

Reproduction

Unfortunately I cannot post any code since this is a private repo but the build fails on my package that get's imported from my organisation's monorepo (lerna, workspaces).

System Info

System:
    OS: macOS 11.5.2
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 318.47 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 12.22.7 - ~/.nvm/versions/node/v12.22.7/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 6.14.15 - ~/.nvm/versions/node/v12.22.7/bin/npm
  Browsers:
    Brave Browser: 97.1.34.81
    Chrome: 97.0.4692.99
    Chrome Canary: 100.0.4862.3
    Edge: 97.0.1072.76
    Firefox: 91.0.2
    Firefox Developer Edition: 97.0
    Safari: 14.1.2
  npmPackages:
    @vitejs/plugin-react: ^1.0.7 => 1.1.4 
    vite: ^2.7.2 => 2.7.13

Used Package Manager

yarn

Logs

[vite:esbuild] failed to resolve "extends":"../../tsconfig.json" in /Users/me/my-app/node_modules/@my-library/my-package/tsconfig.json
file: /Users/me/my-app/node_modules/@my-library/my-package/index.ts
error during build:
TSConfckParseError: failed to resolve "extends":"../../tsconfig.json" in /Users/me/my-app/node_modules/@my-library/my-package/tsconfig.json
    at resolveExtends (/Users/me/my-app/node_modules/vite/dist/node/chunks/dep-f5552faa.js:22291:11)
    at parseExtends (/Users/me/my-app/node_modules/vite/dist/node/chunks/dep-f5552faa.js:22275:34)
    at parse$e (/Users/me/my-app/node_modules/vite/dist/node/chunks/dep-f5552faa.js:22226:24)
    at async loadTsconfigJsonForFile (/Users/me/my-app/node_modules/vite/dist/node/chunks/dep-f5552faa.js:22567:24)
    at async transformWithEsbuild (/Users/me/my-app/node_modules/vite/dist/node/chunks/dep-f5552faa.js:22404:36)
    at async Object.transform (/Users/me/my-app/node_modules/vite/dist/node/chunks/dep-f5552faa.js:22488:32)
    at async transform (/Users/me/my-app/node_modules/rollup/dist/shared/rollup.js:21959:16)
    at async ModuleLoader.addModuleSource (/Users/me/my-app/node_modules/rollup/dist/shared/rollup.js:22192:30)
[!] Error: unfinished hook action(s) on exit:

Validations

Niputi commented 2 years ago

adding @dominikg as you made tsconfk and might know the reason

dominikg commented 2 years ago

It looks like that package extends a tsconfig that is outside of it's own directory. "extends":"../../tsconfig.json" in /Users/me/my-app/node_modules/@my-library/my-package/tsconfig.json would be /Users/me/my-app/node_modules/tsconfig.json

Does that file exist? I guess not. Also i'm not sure why there is typescript in node_modules. shouldn't that be a built version of my-package? This might have something to do with lerna (not familiar with it) but without a reproduction, i'm not sure what could be going on here.

github-actions[bot] commented 2 years ago

Hello @iakovosvo. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

TeckTn commented 2 years ago

I have exactly the same issue with this package : @axa-fr/react-oidc-redux You could add it and you will see that yarn build faild with the same error message.

I use react-ts template with yarn 3 with pnp mode.

dominikg commented 2 years ago

I have exactly the same issue with this package : @axa-fr/react-oidc-redux You could add it and you will see that yarn build faild with the same error message.

see https://github.com/AxaGuilDEv/react-oidc/issues/671

it seems in that case the issue is that their package.json contains a legacy "jsnext:main" entry that takes precedence in vite. @iakovosvo you may want to check your project for a similar field

I use react-ts template with yarn 3 with pnp mode.

esm support with yarn pnp has been less than pleasant (read: not working) in the past. does it work now?

TeckTn commented 2 years ago

Thank's for your answer. Yarn dev works perfectly. I have only this issue with yarn build.