privatenumber / esbuild-loader

💠 Speed up your Webpack with esbuild ⚡️
MIT License
3.58k stars 106 forks source link

jsxImportSource not recognized with esbuild-loader@3 #312

Closed vire closed 1 year ago

vire commented 1 year ago

Bug description

before: esbuild-loader@npm:2.21.0

const icon = (name) => /* @__PURE__ */ (0,_emotion_react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsx)("svg", { children: /* @__PURE__ */ (0,_emotion_react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsx)("use", { /*omitted */ }) });

after: esbuild-loader@npm:3.0.0

const icon = (name) => /* @__PURE__ */ React.createElement("svg", null, /* @__PURE__ */ React.createElement("use", { /*omitted */ }) });

tsconfig.json

  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "@emotion/react",
    "importsNotUsedAsValues": "remove",
    "noUnusedLocals": true,
    "experimentalDecorators": true,
    "incremental": true
  },

webpack module.rules

{
  test: /\.tsx?$/,
  loader: 'esbuild-loader',
  options: {
    loader: 'tsx', // Or 'ts' if you don't need tsx
    target: 'es2017',
  },
},

Reproduction

I've upgraded existing repo just by yarn up esbuild-loader

Node.js package manager

yarn

Environment

"esbuild": "^0.17.6", "esbuild-loader": "^3.0.0",

Binaries:
    Node: 16.18.1 - 
    Yarn: 3.3.1 -  
    npm: 8.19.2 -

Can you contribute a fix?

privatenumber commented 1 year ago

I can't really help based on how little information you've provided.

Did you read the migration guide? https://github.com/esbuild-kit/esbuild-loader/releases/tag/v3.0.0

It might be because your tsconfig.json doesn't include that file. If not, can you provide a minimal reproduction?

vire commented 1 year ago

It might be because your tsconfig.json doesn't include that file.

So my use-case is a NX monorepo where the apps/main imports some code from libs/my-custom-lib and I've noticed that the imports from libs/my-custom-lib aren't transformed with the tsconfig that is specified in the apps/main webpack/esbuild-loader deifniton...

so there was a BC I'm not aware of...

and yes - the imported local library files is not part of the apps/main/tsconfig.app.json includes/files - but why it should be when it's a typescript path alias?

privatenumber commented 1 year ago

I don't really follow what you're saying. Your tsconfig.json above doesn't even contain any path aliases. Please provide a minimal reproduction so I don't need to keep asking questions about your setup.

vire commented 1 year ago

I will try to prepare a sample app reproducing my setup - I'm currently working on a huge monorepo with a lot sensitive data so extracting configs is quite tedious, I will try my best to provide good repro steps ASAP

privatenumber commented 1 year ago

My go-to technique for creating a minimal reproduction is to duplicate the repo and delete everything irrelevant to the bug.

privatenumber commented 1 year ago

Will re-open once the minimal reproduction is provided.