esbuild-jest icon indicating copy to clipboard operation
esbuild-jest copied to clipboard

Don't working with jsx: preserve

Open polRk opened this issue 3 years ago • 9 comments

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 avatar May 17 '21 13:05 polRk

Inject maybe can help

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

polRk avatar May 17 '21 13:05 polRk

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

aelbore avatar May 20 '21 16:05 aelbore

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

polRk avatar May 20 '21 16:05 polRk

@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 https://github.com/aelbore/esbuild-jest/pull/34 and try with your codebase everything should work fine

semoal avatar May 23 '21 23:05 semoal

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.

IvanRodriCalleja avatar May 27 '21 22:05 IvanRodriCalleja

Any update on this?

imjordanxd avatar Jun 11 '21 00:06 imjordanxd

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?

vasilii-kovalev avatar Jul 21 '21 10:07 vasilii-kovalev

Maybe this repo can solve problem

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

polRk avatar Jul 30 '21 13:07 polRk

Maybe this repo can solve problem

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

I've had better luck with this one so far

jasonwilliams avatar Mar 11 '22 12:03 jasonwilliams