-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot compile TypeScript app created with CRA because of parsing errors #9791
Comments
Interestingly, I just tried this on Ubuntu 18.04 with the exact same node/npm versions. It's compiling there:
I also just tried it on another (complete fresh) install of Windows 10 x64 on another computer (with node 12.16.3 and npm 6.14.4). That machine fails exactly like in the bug report above. Please help - we're unable to build or product on any new Windows machines right now! |
This is no longer reproducible (but still occurs in another project of ours), so something bad had been published. Unsure how to fix in other project. |
I'm having the same problem and have been having it since once of the pre-releases. I've gathered that it may be an issue with |
Okay, scratch that. After comparing the output of a fresh
This was missing in the app I upgraded. Presumably this was added to the generator output at some point in the past but inferred if missing and that logic got canned at some point in the 4.0.0 pre-releases, breaking old apps that were missing this bit. Adding this to my |
@pluma Thank god! I was dealing with this all day... I even tried to migrate to snowpack, but that is even more pain... |
This doesn't work for me. I already had this in my "eslintConfig": {
"extends": "react-app"
}, I changed it to this: "eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
}, I'm still having the same problem -- the project still fails to build on syntax like |
Not sure why yet, but the thing that has solved this problem for me was deleting an .eslintrc file I had in the root folder |
Thanks. Doesn't work for me - I don't even have that file. |
I did some digging and it seems like this was introduced by the changes to ESLint config handling in v4.0 (see https://github.com/facebook/create-react-app/pull/9587/files#diff-8e25c4f6f592c1fcfc38f0d43d62cbd68399f44f494c1b60f0cf9ccd7344d697L372 and then https://github.com/facebook/create-react-app/pull/9640/files#diff-8e25c4f6f592c1fcfc38f0d43d62cbd68399f44f494c1b60f0cf9ccd7344d697R366). In particular, the default lint config is now using
Likely solution is to move TS-aware parser config to the base file? |
Thanks. Unsure how to test your solution - could you provide a short step-by-step? I'll test it out because I still can't build the project on Windows. |
Sorry @philiparvidsson, I meant that as a suggestion for a general fix in the CRA source code. In your particular situation it does sound like there is something interfering with your lint config, maybe there is a way to get eslint to dump configuration for further debugging? The workarounds from other commenters worked ok for me. |
Thanks. Yes, something is indeed interfering. The project was untouched but just stopped building after a while (after removing node_modules and doing |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
Hi @philiparvidsson, I have just suddenly begun receiving the exact same error out of nowhere, for no reason. Also running Windows. It just broke from one moment to the next.
The problem is that "4:30" literally does not exist. There is no line 4 which has 30 positions, and the pinpointed code snippet is actually line 1. And it is completely harmless, regular code, which has worked the entire time. Position 30 is a space. If I add a comment in the file, the error jumps to another file. If I keep adding comments, eventually it comes back to /Sanity.ts, but 5:30 instead of 4:30. Have you been able to fix the problem for yourself? |
In the line you pasted ( I haven't built the project in a long time on Windows (our build system is Linux and it's working there). Just to give you an answer, I pulled everything to yet another Windows machine (pretty clean install) and ran the CI build script which works on Linux (basically all it does is Just to inform you: It's still broken. Just before I reported this bug, I could build fine on Windows. But since the report, the build is entirely broken on Windows. We've tried recreating the project, recreating package.json (by manually reinstalling every package with So no, I'm not able to fix it. The best suggestion I can give you is to run your builds in Docker, WSL or on a Linux-machine. |
To give an update on my comment yesterday, I was able to resolve my personal problem, which probably ended up unrelated to this topic after all. My issue was that my project is split into different modules - "client", "shared" and "server", and I was including the "shared" module in my "client" without transpiling the TS first. (Via The baffling part is that I have been using the shared package for weeks without the error appearing, and then it suddenly popped up out of nowhere. The correct solution is probably to just transpile the shared package before using it, but what I did instead was to install CRACO and change the CRA webpack config to add an additional rule:
craco.config.js: const path = require("path");
module.exports = {
webpack: {
configure: webpackConfig => {
// ts-loader is required to reference external typescript projects/files (non-transpiled)
webpackConfig.module.rules.push({
test: /\.ts(x)?$/,
loader: 'ts-loader',
include: [
path.resolve(__dirname, '../your/local/path'),
path.resolve(__dirname, '/node_modules/your-local-package-name'),
],
options: {
transpileOnly: true,
configFile: 'tsconfig.json',
},
})
return webpackConfig;
}
}
}; and then replace The problem also happened in WSL2, which tipped me off to the thought that it might not be Windows-related after all. While my woes ended up not directly related, I hope that the context may provide some ideas for solving this particular case. |
Something I don't understand is why would |
@yoruvo Thanks for this, helped diagnose something similar happening for me. I've had this issue with a Any time it hits TS syntax in that file, I get the same error:
If I copy the code into a "proper" file in the same place, it works without issue. It also works if there's no Typescript-specific syntax in the file. With the symlink it seems to be skipping TS transpilation entirely. From digging a bit deeper it looks like my issue (and maybe yours?) is more #3547 |
deleting the eslintrc file helped me |
This fixed for me as well. I just saw that this code is in basic CRA too. I might have deleted it at some point. |
for me, My eslintrc does not use I do not have an Bizarre issue. |
I came across this when trying to upgrade my company's create-react-app from v3→v4. The migration path doesn't note that you will lose ESLint capabilities unless you specify `eslintConfig` explicitly in your `package.json` going forward. Progression of ESLint changes in Webpack: - removal of original extend and addition to `template.json`: https://github.com/facebook/create-react-app/pull/9587/files - referencing of /base instead of /index: https://github.com/facebook/create-react-app/pull/9640/files#diff-8e25c4f6f592c1fcfc38f0d43d62cbd68399f44f494c1b60f0cf9ccd7344d697R366 This was also noticed by other developers in these bugs: facebook#9791 facebook#10212
I have the same situation as @tetchel . I have a client (cra) and server (fastify) setup, and its much better to have one eslint config, kept in the root folder of both apps. So i deleted esling from client package. And now when i put my client part into docker, without eslint config, it cannot compile ts. WHY? :D |
Oh god, I had the same issue, another gotcha is |
For anyone else landing here, and not thinking that linting has anything to do with the error you are having. I just found out that CRA always adds ESLint so it will run even if you remove all your ESLint config. And then it will crash because ESLint without config cannot handle TypeScript. The fix is to add back:
to your |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
Describe the bug
create-react-app
seems to have issues compiling valid TypeScript code.Did you try recovering your dependencies?
Yes, in a number of ways. I cannot manage to fix this, despite spending hours on researching it.
I've tried:
node_modules
and doingnpm install
andnpm ci
package-lock.json
andnpm install
andnpm ci
package.json
file by doingnpm install <package-name>
for every single dependency.Which terms did you search for in User Guide?
parsing error, unexpected token, syntax error, create-react-app, private access modifier, failed to compile, typescript syntax error and tons of permutations of these.
Environment
Steps to reproduce
npx create-react-app my-app --typescript
App.tsx
and add the following code under the import statements and above thefunction App() ...
line:Full content of
App.tsx
:npm run build
NOTE: There are other syntaxes which do not work, such as
readonly
and more.Expected behavior
The app is compiled successfully.
Actual behavior
The text was updated successfully, but these errors were encountered: