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

Don't working with jsx: preserve #37

Open
polRk opened this issue May 17, 2021 · 9 comments
Open

Don't working with jsx: preserve #37

polRk opened this issue May 17, 2021 · 9 comments

Comments

@polRk
Copy link

polRk commented May 17, 2021

tsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "lib": [
      "DOM",
      "DOM.Iterable",
      "ESNext"
    ],
    "allowJs": false,
    "skipLibCheck": false,
    "esModuleInterop": false,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "declaration": true,
    "sourceMap": true
  }
}

Button.tsx

import type { FC } from 'react'


export interface IButtonProps {}


export const Button: FC<IButtonProps> = function ({children}) {
  return <button>{ children }</button>
}

Error

ReferenceError: React is not defined
@polRk
Copy link
Author

polRk commented May 17, 2021

Inject maybe can help

https://esbuild.github.io/api/#inject

@aelbore
Copy link
Owner

aelbore commented May 20, 2021

@polRk can i know whats your jest config? you try to include jsx in the config, thanks

@polRk
Copy link
Author

polRk commented May 20, 2021

module.exports = {
  setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
  transform: {
    '^.+\\.tsx?$': [
      'esbuild-jest',
      {
        sourcemap: true,
        loaders: {
          '.spec.tsx': 'tsx',
        },
      },
    ],
  },
}

@semoal
Copy link

semoal commented May 23, 2021

@polRk can i know whats your jest config? you try to include jsx in the config, thanks

It's the same error that I've reported about coverage failing, in your tests fails about semicolon but in large projects fails about React is not defined.
I'm sure that @polRk if you clone my changes #34 and try with your codebase everything should work fine

@IvanRodriCalleja
Copy link

I thin right now you can not use the inject configuration property in esbuild-jest until some PR like #29 is merged. I hope it will soon.

@imjordanxd
Copy link

Any update on this?

@vasilii-kovalev
Copy link

Doesn't work with react-jsx as well. Would be great to replace ts-jest, but it is not possible because of this issue.
What's the status of it?

@polRk
Copy link
Author

polRk commented Jul 30, 2021

Maybe this repo can solve problem

https://github.com/hannoeru/jest-esbuild

@jasonwilliams
Copy link

Maybe this repo can solve problem

https://github.com/hannoeru/jest-esbuild

I've had better luck with this one so far

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants