Skip to content
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@beta moduleResolution nodenext strategy breaks @emotion #2742

Closed
noahehall opened this issue Apr 30, 2022 · 6 comments
Closed

Typescript@beta moduleResolution nodenext strategy breaks @emotion #2742

noahehall opened this issue Apr 30, 2022 · 6 comments
Assignees
Labels

Comments

@noahehall
Copy link

noahehall commented Apr 30, 2022

Current behavior:

  • setting tsconfig.json.moduleResolution = node: everything is fine
  • setting tsconfig.json.moduleResolution = nodenext: throws error
./src/app.tsx 13:2-15:21
[tsl] ERROR in /somedir/nirv/src/app.tsx(13,3)
      TS2307: Cannot find module '@emotion/react/jsx-runtime' or its corresponding type declarations.

Expected behavior:

Environment information:

  • react version:18.1
  • @emotion/react version:18.1
  • typescript: beta
  • tsc: Version 4.7.0-dev.20220430
  • pnpm: 6.32.9

** tsconfig **

{
  "include": ["src"], 
  "exclude": ["src/**/*.test.ts"],
  "compileOnSave": false,
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "alwaysStrict": true,
    "baseUrl": "./", 
    "checkJs": false,
    "esModuleInterop": true,
    "exactOptionalPropertyTypes": false,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "jsx": "react-jsx",
    "jsxImportSource": "@emotion/react",
    "lib": ["dom", "dom.iterable", "esnext"],
    "module": "esnext", 
    "moduleResolution": "nodenext", <-------- breaks @emotion 
    "noFallthroughCasesInSwitch": false,
    "noImplicitAny": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noPropertyAccessFromIndexSignature": false,
    "outDir": "dist",
    "paths": {},
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true,
    "target": "es2017", 
    "typeRoots": ["./src/@types", "./node_modules/@types"]
  }
}
@srmagura
Copy link
Contributor

srmagura commented May 1, 2022

Thanks for the report, I can confirm this is an issue. Minimal repro: https://github.com/srmagura/emotion-nodenext-repro

@Andarist
Copy link
Member

Andarist commented May 1, 2022

So the way to fix this would be to add the appropriate package.json#exports. This is, sort of, worked on here: preconstruct/preconstruct#435

@noahehall
Copy link
Author

noahehall commented May 1, 2022

thank you guys! I will review preconstruct#435

@srmagura
Copy link
Contributor

This should be fixed by #2819. Will test this once against that PR once it is finalized. Test repo

@srmagura srmagura self-assigned this Jul 11, 2022
@koistya
Copy link

koistya commented Jul 31, 2022

Testing @emotion/react (jsx-runtime) 11.10.0 with TypeScript 4.7.4 and moduleResolution = NodeNext.
It seems to be working as expected (in react-starter-kit).

@Andarist
Copy link
Member

Andarist commented Aug 1, 2022

Thank you for reporting back about this 🎉

@Andarist Andarist closed this as completed Aug 1, 2022
Offroaders123 added a commit to Offroaders123/Dino-TSX that referenced this issue Jun 9, 2023
Unfortunately it didn't work because of ESM challenges, but tried changing the `jsx` flag to use `react-jsx` instead.

https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax (Tried to upgrade from `importsNotUsedAsValues`, but things are still broken in regards to import elision)
https://www.typescriptlang.org/tsconfig#jsx
microsoft/TypeScript#47804
emotion-js/emotion#2742
https://www.typescriptlang.org/tsconfig#paths (Also tried setting `jsxImportSource`, but that breaks in ESM because of the forced module resolution path `_ident_/jsx-runtime` :{ )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants