-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Typescript classes not working in components-typescript #29
Comments
By investigating further, I've found that this might be related to the lint module in If I exclude typescript files from this step, the app is able to build (line 369): // First, run the linter.
// It's important to do this before Babel processes the JS.
{
- test: /\.(js|mjs|jsx|ts|tsx)$/,
+ test: /\.(js|mjs|jsx)$/, But it's not a viable option, as it disables all linting. Another "fix", is to only include the source of the app in the lint step: loader: require.resolve('eslint-loader'),
},
],
- include: includePaths,
+ include: [includePaths[0]], This is not ideal, but it keeps the lint rules for the application and allows typescript features (classes, casting, etc) in external components. I have not found a solution that lints both the app and external components, while maintaining support for the above mentioned typescript features. |
Perhaps we can convince @pmoleri to look into this? @pmoleri had PR'ed TypeScript into the codebase originally. See: react-workspaces/create-react-app#3 I'm not a TypeScript developer, so perhaps I'm going to be slow debugging this one. :( @jmyrland - Do you think the errors are actually being thrown at the linting stage or the transpile stage, or both? Also... Is it possible this is an issue with your Ie: is it possible you are using See:
It is also possible that this is a linting configuration. We have linting installed in root, but I had set that up before TypeScript, so perhaps something is off. If you have a repo somewhere I can pull your setup, I will see if I can get it running. |
Thanks for your reply! I'm writing this "on the go" so I do not have all the details regarding your questions - but I will provide this as soon as I'm in front of my computer 🙂 I believe it's only affecting the lint stage, as the code executes correctly (but I'm not 100% certain) If you drop in that class in one of the components (in the components-typescript package), an error will be displayed when running app-typescript so it is easily reproducible. I believe it is the same case regarding #28. I'll fork the repo and give you a link for a reproducible case 👍 I am not that familiar with the CRA webpack config, so I am not exactly sure how to fix this 100% but the last adjustment to the config works in my case (it runs the app correctly) - but I do not know what side effects this change has (besides not linting external components). I'm certain there is a better solution to this problem. I'll be happy to help however I can 🙂 |
I didn't understand the problem in my previous comment so I deleted it. But I think I've found a solution. By can setting the environment variable The react-app configuration sets an override for .ts/tsx files using the glob: |
Ah! That sounds right. Interested in throwing a PR together? |
@F1LT3R : I've made a reproducable example here: jmyrland#1 I'll try the changes suggested by @SyedRFarhan to see if this circumvents the errors 👍 |
After adding an |
Where are you placing this |
@abrkn I placed it inside the |
@abrkn check out this commit: jmyrland@97e47f2 I've removed the "custom" eslint rules by default, and only extended the "standard" rules from CRA - as it might make it easier to migrate projects :) |
+ Adds .env file to extend eslint + Adjusted eslintrc.js to be based on CRA by default
Is there any way to get the I suppose it doesn't matter for now, but I had previously thought the practice of relying on env files for your react app was discouraged? Perhaps this was only discouraged for certain kinds of settings. |
It is an opiniated topic 😁 This is what the official CRA docsstates regarding
|
☝️ makes sense I had encountered CRA Monerepo configuration issues when previously using incompatible versions of things like eslint and WebPack that were clobbering each other when not being hoisted, or the setup had apps using multiple versions of CRA. See: https://f1lt3r.io/create-react-app-monorepo-with-lerna-storybook-jest#create-your-react-app Package versions are a much more dangerous class of problem. But I can't think of a good reason why your use of the .env file for the listing extension would be a problem. |
Hi. When I first implemented the changes for TypeScript I found this same issue. At that time I decided to disable linting outside the main project. I guess that this change was overwritten when updating to CRA 3.0. It seems that your solution is even better because it actually lints the dependent code, right? |
First off, great job on this repository @F1LT3R ! 👏
I'm having some issues in regards to using classes in the shared
components-typescript
library.If I add a class to the
CompTwo.tsx
component:I get the following error when starting
app-typescript
:Is there a quick fix to this issue, or some configurations that I am not aware of?
Related issues: #18, #28
The text was updated successfully, but these errors were encountered: