create-react-app: Build error `no-undef` for flowtypes with class properties
Can you reproduce the problem with npm 4.x?
Yes
Description
An error when running yarn run build
occurs if I add a class property with a type to a react component. E.g.
interface MyType {
what?: string;
}
// works fine
var status: MyType = {};
console.log(status);
class App extends Component {
// no-undef build error
state: MyType = {};
render() {
...
Expected behavior
✨ Done in 11.24s.
Actual behavior
./src/App.js
Line 16: 'state' is not defined no-undef
Search for the keywords to learn more about each error.
error Command failed with exit code 1.
Note that yarn run flow
raises no issue. So I’m guessing it’s an eslint problem but there’s no way to tell from the build output. Would be nice if the errors were tagged with their source (vs code does this in the problems
panel).
Environment
Run these commands in the project folder and fill in their results:
npm ls react-scripts
(if you haven’t ejected): react-scripts@1.0.7node -v
: v7.9.0npm -v
: 4.6.1
Then, specify:
- Operating system: macOS 10.12.5 (16F73), uname -a: Darwin yuv 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64
- Browser and version: This is a command line build issue
Reproducible Demo
https://github.com/ubershmekel/create-react-app-flowtypes
Related to
https://github.com/kitze/custom-react-scripts/issues/12 https://github.com/facebookincubator/create-react-app/pull/567
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 6
- Comments: 16 (10 by maintainers)
@gaearon I just updated to the newest CRA and this seems to have popped up again for me. I’m wondering now that CRA uses eslint 4 is this is a bug now? Is anyone else running into this?
In the meantime, downgrading my own version to 3.19 cleared everything up.
i my case conflict with react-script removing react-script solved my problem
+1, still getting this
In
v4.13.1
, stil popI gave this a 👍 earlier, but I just downloaded your example and can’t reproduce the error. I’m using Node 7.10.0, if it matters.
The weird part is, I can still reproduce similar problems on my own project. For one of my components:
results in:
'props' is not defined no-undef
Weirder still, and I’m not sure if it’s related, I have another component where adding an arrow function property:
results in:
'handleChange' is not defined no-undef
But weirder still, changing the method’s name to
test
works fine:I can’t pin down an exact pattern, but I feel like this is all related. Thoughts?