-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
(RTK Alpha 2): Cannot resolve types when moduleResolution
is set to node16
#3202
Comments
Oh boy. Honestly I've never even tried to mess with TS's resolution options. I've seen a couple of the discussion threads, but I really don't know what's actually needed for any of that. I'm really not a fan of the |
I feel you. It's been a painful transition going into ESM. I've been searching long and wide for some backwards compatibility. I have some packages that rely on the 'exports' attribute in their As far as this reads, the extensions are required: https://nodejs.org/api/esm.html#mandatory-file-extensions There's an eslint plugin that has helped me transition to these ESM requirements: eslint-plugin-require-extensions. Allows Ecosystem is in a limbo, haha. |
If I'm reading https://twitter.com/AndaristRake/status/1629168415175835649 correctly, the suggested fix here is actually to drop |
Hello guys; I hope you are doing well. I did reproduce this issue in this repo (if you want it as a starting point): https://github.com/incepter/alpha-toolkit-test Actually, the solution turns to be quit simple: Just remove |
Thank you! Unfortunately, removing the @incepter I ran into some similar problems when trying to output some declaration files with # ...
src/Toggle.tsx:7:41 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("@reduxjs/toolkit")' call instead.
To convert this file to an ECMAScript module, add the field `"type": "module"` to './alpha-toolkit-test/package.json'.
7 import { ActionReducerMapBuilder } from "@reduxjs/toolkit";
# ... |
Sorry, but unfortunately that's incorrect. You'd need to switch the ESM entries in This is the direction the TS team have chosen to go (sadly), you'll need your |
Well, frankly, now I'm completely lost. Seriously. I don't know what I am supposed to do :( |
So this particular issue is quite simple, you just need to ensure the The desired output of ...
-export { createDraftSafeSelector } from './createDraftSafeSelector';
+export { createDraftSafeSelector } from './createDraftSafeSelector.js';
... I haven't taken a peek at your build tooling (or attempted to run it), but in theory, it should be as simple as altering this:
to be this: export { createDraftSafeSelector } from './createDraftSafeSelector.js' Running |
Seems like microsoft/TypeScript#49160 is a related "everything is broken now" issue. |
I realize this is going to sound petty and has no sound basis. But that looks stupid, and I really don't want to do that :( |
https://arethetypeswrong.github.io/ looks useful |
I do agree, but sadly, that's their direction and they're seemingly sticking to it. You could always merge type declarations, so there's a mega |
So I started patching I'm about convinced this effort to support I don't know. I am definitely looking forward to updates from that discussion mentioned on Twitter. |
I fear we don't really getting around those .js endings in our sources. They look super weird but the TS team is pretty set that the compiler should not rewrite file names, so this is the direction to go.
|
I really, really don't want to do that :( |
I created the needed patches to the Redux alpha package family to resolve this types issue. Might be helpful to those that use PNPM or Yarn and still want to experiment with the alpha: https://github.com/eric-crowell/redux-toolkit-alpha.2-patches/tree/main/patches I had to export some additional types too or else encounter the error I wouldn't mind working this effort to add the extensions for alpha 3 (or as you like). That way, you wouldn't have to focus on it too much. Maybe IDEs can optionally hide them for aesthetic purposes soon. If it's any consolation, I am also sad about the lack of alternatives. |
If anything, I'd rather investigate a new build step to rewrite the generated |
Alright. I suppose there's a need to wait on some of those test apps against the build output then. Otherwise, could be worth looking into running several instances of Want to help out where I can. Really do appreciate everything! |
@eric-crowell : that's roughly what I'm attempting over in #3213 . Yesterday I managed to get a PR initially passing that takes the packed artifact we were already generating (eh... technically I skipped the "generated" part because I needed to iterate faster on the GH Actions job and Playwright step, but that part works already), installs it into a CRA 5 app, builds it, and runs a Playwright test that verifies basic functionality (counter increments, two RTKQ APIs run (with and without React)). I had done some work a few weeks ago to make local projects for CRA, Next, Vite, and Expo. So now that I can do that for one example, I can start copy-pasting the example projects in and matrix them. That will help verify that any given PR builds and runs correctly. Once I get that working for 1.9.x on Actually, if you or someone else really wants to help... you could start filing PRs targeted at that PR to add equivalent setups for a variety of apps built with different tools. Off the top of my head, I'd like to target:
The other immediately open question would be how to do the equivalent of a Playwright test for an RN app. I'm sure there's something similar, I just haven't looked (and I don't use RN myself). The app code in the example should be portable across all the examples (store setup, RTKQ API definitions, most of the components). The components would need to be redone for the RN examples (and I have a couple of those bashed together locally I think). So, porting the example app setups would be a huge help! |
Awesome- so if I understand correctly, one would...
I haven't started a RN app in quite some time. It looks like they mentioned Detox for end-to-end testing on their site: https://reactnative.dev/docs/testing-overview#end-to-end-tests |
@eric-crowell : pretty much, yeah. I've actually got Next and Vite examples running locally from when I was playing with this a few weeks ago, so let me go ahead and add those to my PR. If you can tackle any of the others, that'd be great! For RN, we don't have official Redux templates, but there's a couple unofficial templates at https://github.com/rahsheen/react-native-template-redux-typescript and https://github.com/rahsheen/expo-template-redux-typescript . |
@markerikson Sounds good! Following your examples, I'll start by giving a swing at Expo React Native- |
@eric-crowell : I was thinking about it this morning, and I'm now actually wondering if it makes sense to keep these "CI Examples" in a separate repo. We're going to be making similar build tooling changes for the various other Redux repos ( Tell you what. Go ahead and file PRs that target this branch for now, and we can extract them to their own repo later. |
@markerikson That's not a bad idea! If you're wanting to do create the new repo soon, I still need some time for this PR. I can create a new branch and copy the work over to it. No problem. End-to-end tests for React Native projects certainly aren't as straight forward. More extensive with needing emulators and specific SDKs. Here's the PR I was testing with on my own forked repo: eric-crowell#1 The build is working with Metro from what I see reading the cli output. However, getting a virtual device for Detox to use (on GitHub Actions) is where I left off. Maybe someone out there has a good simple workflow setup with Detox I can follow. |
@markerikson Here's my completed setup of a React Native (w/ Metro bundler) end-to-end test project, which very closely mirrors your I'll update that project along with changes made in #3213 . Don't want to step on any toes as you make your refinements. |
@eric-crowell : awesome! haven't had time to touch this since I put up that PR, but I'm doing some traveling next week and may work on it while I'm flying. |
Safe travels! |
@eric-crowell : I may have changed my mind one more time :) All of the other repos (Redux core, Reselect, React-Redux) would need to clone a repo to get their hands on these example projects in their CI jobs, in order to do the install + build + test steps... but if they have to clone a repo anyway, it could be this repo instead of a separate repo. Actually going to spend today's flying time focusing on some docs feedback I just got ( reduxjs/redux#4495 ), but very much still intending to get more example apps integrated into that branch ASAP. |
I think we can call this issue fixed as of the latest 2.0 alphas. |
Hi @markerikson
Occurs when trying to import the {
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
|
@ryerrappa please open up a new issue, and include a repo that shows this happening. We specifically removed all the |
Thank you for the prompt response. I've created an issue here: #3970 |
Type portability issues should be fixed in https://github.com/reduxjs/redux-toolkit/releases/tag/v2.2.7 ! |
A follow up on #2485. When importing anything from
@reduxjs/toolkit@2.0.0-alpha.2
, typescript cannot resolve types whentsconfig.json
'smoduleResolution
is set tonode16
ornodenext
.I found that adding the extension
.js
to the declaration imports resolved the issue. For example....In my file:
./node_modules/@reduxjs/toolkit/dist/index.d.ts
export { createSlice, } from './createSlice';
->export { createSlice, } from './createSlice.js';
Two suggestions for a fix: First, maybe the easiest, is add a post build script to add the extensions to the output. Or second, a search and replace to add the extensions to the all the relevant source files. Want to get some thoughts on a direction before attempting a PR. Maybe there's a better way.
I tried looking to see if typescript can just add them while compiling... but didn't find anything that could.
The text was updated successfully, but these errors were encountered: