Preact-cli: TypeError: Cannot read property 'flags' of undefined

Created on 3 Mar 2020  路  16Comments  路  Source: preactjs/preact-cli


Do you want to request a _feature_ or report a _bug_?
A Bug

What is the current behaviour?
Running yarn run build when installing @types modules breaks the build.

After installing the Typescript template, I'm trying to install styled-components, all goes fine until I install @types/styled-components.

If the current behaviour is a bug, please provide the steps to reproduce.

  1. preact create typescript my-project
  2. yarn add styled-components
  3. yarn add -D @types/styled-components
  4. yarn run build
  5. INTERNAL ERROR: Cannot read property 'flags' of undefined

What is the expected behaviour?
Being able to install @types packages.

OS: macOS 10.15.3
Terminal: Hyper 3.1.0
Shell: zsh
Node: v13.8.0
npm: 6.13.7
preact-cli: 2.2.1

upstream

All 16 comments

It seems to be an issue with typescript itself. There is an open issue in typescript for the same.

Reference link: https://github.com/microsoft/TypeScript/issues/37165

Same problem for me with a fresh installed "preact create typescript my-project"

I build a small Dockerfile which builds my project inside a container which works fine:

FROM node:13
WORKDIR /usr/adminui
COPY . .
CMD npm install && npm run build && mv build output

and run it with:

docker build --rm -t imagetest .
docker run -v build:/usr/src/app/output:rw imagetest

Commenting out the lines in src/declaration.d.ts made the error go away. But removing the lines might break something else.

Does anyone know if the declaration.d.ts file is still needed? According to the TypeScript's documentation, TS is able to pick the right JSX declaration from the factory function in use (https://www.typescriptlang.org/docs/handbook/jsx.html#factory-functions), so when using h it will automatically look for h.JSX which is defined in preact's type definitions (similar story with createElement in compat mode).

As far as I can tell, removing this from a newly created project does not break anything, so unless there's any other reason for having these re-declarations, could this simply be removed to get rid of the tssserver problem?

Does anyone know if the declaration.d.ts file is still needed? According to the TypeScript's documentation, TS is able to pick the right JSX declaration from the factory function in use (https://www.typescriptlang.org/docs/handbook/jsx.html#factory-functions), so when using h it will automatically look for h.JSX which is defined in preact's type definitions (similar story with createElement in compat mode).

As far as I can tell, removing this from a newly created project does not break anything, so unless there's any other reason for having these re-declarations, could this simply be removed to get rid of the tssserver problem?

I added that, and it was just to allow the test lib to run. Nothing more. Definitely get rid of it. It was a temporary hack so all parts of the template "worked".

@RyanChristian4427 thanks for confirming that. Already removed in PR https://github.com/preactjs-templates/typescript/pull/25 which is now awaiting review.

Glad to hear it.

commenting out the declaration.d.ts brings in new errors:

Image 2020-05-17 at 9 14 44 PM

commenting out the declaration.d.ts brings in new errors:

Image 2020-05-17 at 9 14 44 PM

It's definitely going to depend on the libraries you add to the project, but declaration.d.ts exists in the Typescript template for Preact to satisfy Jest Render Spy. As @mdziekon is removing Jest Render Spy, it is fine for that (declaration.d.ts) to be removed from the template.

I definitely don't recommend keeping that there, as it is incredibly finicky (as it can cause the TS language server to crash entirely), but find a better solution that works for your situation. Whatever CacheProvider and ThemeProvider are, they're not included with the Typescript template, so maybe open an issue where others can see what libs you're using that causes this.

@RyanChristian4427 It's from emotion and chakra-ui https://gist.github.com/cj/361253bae01789100f58caf064538d62

(there are no type errors when using react)

@RyanChristian4427 It's from emotion and chakra-ui https://gist.github.com/cj/361253bae01789100f58caf064538d62

(there are no type errors when using react)

I know nothing about either of those, but your best bet will be to just create a new issue for this. This issue thread is specifically for the bug/s caused by declaration.d.ts, as it is in template, existing, so I don't think this is the right place.

@RyanChristian4427 wrote:

As @mdziekon is removing Jest, it is fine for that to be removed from the template.

My PR does not remove Jest, but it replaces outdated render spy with Enzyme integration. Just wanted to clarify that to prevent any false assumptions.

@RyanChristian4427 wrote:

As @mdziekon is removing Jest, it is fine for that to be removed from the template.

My PR does not remove Jest, but it replaces outdated render spy with Enzyme integration. Just wanted to clarify that to prevent any false assumptions.

My bad. Late night. Was trying to do that by memory.

@RyanChristian4427 sounds good :)

The template should no longer cause the error

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thangngoc89 picture thangngoc89  路  3Comments

raphaelbauer picture raphaelbauer  路  3Comments

hguillermo picture hguillermo  路  3Comments

zwrawr picture zwrawr  路  3Comments

hardcoar picture hardcoar  路  3Comments