reduxjs/redux-toolkit

Error: Unexpected token: operator (?) in file node_modules/@reduxjs/toolkit/dist/query/cjs/rtk-query.production.min.cjs at 878:32

remarkablemark opened this issue · 2 comments

I have a React Native app (<0.72) which I tried to upgrade RTK to the latest version but I got the build error:

error node_modules/@reduxjs/toolkit/dist/query/cjs/rtk-query.production.min.cjs: Unexpected token: operator (?) in file node_modules/@reduxjs/toolkit/dist/query/cjs/rtk-query.production.min.cjs at 878:32.
Error: Unexpected token: operator (?) in file node_modules/@reduxjs/toolkit/dist/query/cjs/rtk-query.production.min.cjs at 878:32
    at minifyCode (node_modules/metro-transform-worker/src/index.js:101:13)
    at transformJS (node_modules/metro-transform-worker/src/index.js:319:28)
    at transformJSWithBabel (node_modules/metro-transform-worker/src/index.js:410:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.transform (node_modules/metro-transform-worker/src/index.js:571:12)

I ended up updating metro.config.js to resolve node_modules/@reduxjs/toolkit/dist/query/rtk-query.legacy-esm.js instead of the default import (see blog post for more details).

I'm not sure if the issue is coming from modern syntax in the latest RTK version but I am using Node.js 20.

Hmm. I'm confused by the line number 878:32 there. The actual file only has two "lines" since it's minified:

https://unpkg.com/@reduxjs/toolkit@2.2.3/dist/query/cjs/rtk-query.production.min.cjs

But yes, in general, RTK 2.x ships modern JS syntax , and it's up to end users to transpile or pick the "legacy" build if needed.

@markerikson I believe we can ignore the line number in the error as I'm fairly confident it's importing the minified rtk-query.production.min.cjs like you mentioned.

Thanks for confirming that RTK 2 ships with modern syntax and that resolving the legacy build is fine in this situation.