Skip to content

Commit

Permalink
Add comment that can fix TypeScript errors with Yarn (#2800)
Browse files Browse the repository at this point in the history
* Add comment that can fix TypeScript errors with Yarn

With Yarn 2 TypeScript can't find @types/... files in node_modules (because it does not exist). This is a workaround for such situation.

* Mention phpify as a workaround for yarn 2 folder structure
  • Loading branch information
spidgorny authored Mar 31, 2021
1 parent 16f58b9 commit 6bde3cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions create-snowpack-app/app-template-react-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ Open http://localhost:8080 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.

> In case you use yarn version 2 (berry) and have "file not found" errors in the console.
Typescript does not support yarn 2 folder structure directly (yet).
The workaround is to replace the loading of the typescript plugin in snowpack.config.js with a call to [phpify](https://yarnpkg.com/advanced/pnpify).

```json
plugins: [
// '@snowpack/plugin-typescript',
['@snowpack/plugin-typescript', { tsc: 'yarn pnpify tsc' }],
]
```

Issue: [microsoft/TypeScript#28289](https://github.com/microsoft/TypeScript/issues/28289)

More info: https://medium.com/swlh/getting-started-with-yarn-2-and-typescript-43321a3acdee

### npm run build

Builds a static copy of your site to the `build/` folder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module.exports = {
'@snowpack/plugin-react-refresh',
'@snowpack/plugin-dotenv',
'@snowpack/plugin-typescript',
// if using yarn v2 and have 27+ TypeScript errors replace with
// ['@snowpack/plugin-typescript', { tsc: 'yarn pnpify tsc' }],
],
routes: [
/* Enable an SPA Fallback in development: */
Expand Down

1 comment on commit 6bde3cf

@vercel
Copy link

@vercel vercel bot commented on 6bde3cf Mar 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.