-
Notifications
You must be signed in to change notification settings - Fork 492
Cant import regular js files when using create-react-app-typescript #120
Comments
Hm... yes, this is a catch-all clause to cover all files not matching the already listed ones. I agree that it should be possible to use @wmonk , what do you think? |
I use js+dts in conjuction with protobufjs, which generates code and corresponding typings. I suppose this usecase falls under the category of reusing existing javascript libraries which are not written in typescript. Since js+dts Does work for node_modules, it could make sense to not support JS for the package source code. |
The vast majority of "using existing javascript libraries not written in typescript" is covered by modules installed from external sources like the npm repository (so it would be located in node_modules). So it is still somewhat special, though reasonable to import existing (in your case: generated) code from ts. Technically, it's not possible for a transformer to separate between "js files that still have to be transformed" and "js files that may be left as is" with acceptable effort. It is possible to configure this manually as long as there are paths or names to separate these, but it would require ejecting your project to add these capabilities.
(1) should be able to cover your case, but might be too simple for others, while (2) should be able to cover almost every case, but is a bit overkill for simpler ones like yours. |
I would prefer a way to to this without ejecting, but i understand that it is difficult to add this as default behaviour. |
I don't really want to deviate from the |
Has anyone managed this in a CRAT friendly way? I want to use https://devexpress.github.io/devextreme-reactive/react/grid/ but there are no typings yet. |
I ended up creating a proxy around node.require to fix create-react-app-ts from not supporting plain js files. I injectthe proxy before running the regular react-scripts-ts/scripts/test. The proxy adds the necessary config to the createJestConfig file.
Then in package.json i use the following script
Its possible you might need to add some npm packages for the proxy but i dont remember if that was the case or not |
Thanks for that, but I'm not really want to scare my fellow devs with that.) In any case, I want to include javascript files in my regular project, not just the test stuff. |
You probably want to use |
I have some .js + .d.ts files which i am using in my create-react-app-typescript project. Everything works and runs fine with npm run start or npm run build.
When running npm run test, the import statements for these .js files return the name of the file, instead of actually importing the file.
I believe this behaviour is caused by the configuration line in "createJestConfig.js". The matches all .js files and replaces them with stubs:
When adding .js to the ignored transform patterns, the tests correctly import my .js+.d.ts files
I believe this is a bug/oversight in the configuration, since using .js+.dts files as source code is not that strange. In any case i do not think it makes sense to replace all .js files with stubs.
I would love to see this fixed in the project or a way to configure this without the massive workaround i have posted below
Thanks,
MH
PS
I use this workaround to prevent changing the react-scripts ts:
The text was updated successfully, but these errors were encountered: