From dc4e448597b84008d6e452ee67554fb01bc91c24 Mon Sep 17 00:00:00 2001 From: Levente Bagi Date: Fri, 13 Jul 2018 11:54:56 +0100 Subject: [PATCH] add undefined import tip to guide Add troubleshooting tip for importing the default export in TypeScript. Easy mistake to make when migrating from JavaScript. --- packages/react-scripts/template/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index d5b4fc98a..c5fd6149c 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -100,6 +100,7 @@ You can find the most recent version of this guide [here](https://github.com/fac - [`npm run build` fails on Heroku](#npm-run-build-fails-on-heroku) - [`npm run build` fails to minify](#npm-run-build-fails-to-minify) - [Moment.js locales are missing](#momentjs-locales-are-missing) + - [TypeError: Cannot read property _foo_ on undefined](#typeerror-cannot-read-property-foo-on-undefined) - [Alternatives to Ejecting](#alternatives-to-ejecting) - [Something Missing?](#something-missing) @@ -2439,6 +2440,20 @@ To resolve this: In the future, we might start automatically compiling incompatible third-party modules, but it is not currently supported. This approach would also slow down the production builds. +### TypeError: Cannot read property _foo_ on undefined + +When importing a module, you might need to use + +```typescript +import * as foo from 'foo'; +``` + +instead of + +```typescript +import foo from 'foo'; +``` + ## Alternatives to Ejecting [Ejecting](#npm-run-eject) lets you customize anything, but from that point on you have to maintain the configuration and scripts yourself. This can be daunting if you have many similar projects. In such cases instead of ejecting we recommend to *fork* `react-scripts` and any other packages you need. [This article](https://auth0.com/blog/how-to-configure-create-react-app/) dives into how to do it in depth. You can find more discussion in [this issue](https://github.com/facebookincubator/create-react-app/issues/682).