Hello, I'm slowly moving a big react project to preact and as a workaround I have
alias: {
"react": "preact/compat",
"react-dom": "preact/compat",
},
in my webpack config, is there a way to do that with esbuild
?
You should be able to do this with esbuild by creating a tsconfig.json
or jsconfig.json
file that looks something like this:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"react": ["./node_modules/preact/compat"],
"react-dom": ["./node_modules/preact/compat"]
}
}
}
@evanw, @OneOfOne, please tell me if it is possible to specify the path to the alias outside the project directory? These options give an error: "Could not resolve "react"":
"baseUrl": "/home/user/node_modules",
"paths": {
"react": [
"./preact/compat"
],
}
"baseUrl": "."
"paths": {
"react": [
"/home/user/node_modules/preact/compat"
],
}
"baseUrl": "."
"paths": {
"react": [
"../../node_modules/preact/compat"
],
}
"baseUrl": "."
"paths": {
"react": [
"preact/compat"
],
}
Not sure this use case is supported, but, I'm seeing this error in this setup:
node_modules
with npm link
.The parent project has a tsconfig.json
like this:
"baseUrl": ".",
"paths": {
"react": ["node_modules/preact/compat"],
"react-dom": ["node_modules/preact/compat"],
},
I then run this inside of the parent project:
npm link ../child
Then parent uses the child
dependency with a symlink. At this point, esbuild prints:
../child/build/Component.js:1:23: error: Could not resolve "react"
import * as React from 'react';
Again, not sure this is a bug or not, but I thought I'd file this.
Most helpful comment
You should be able to do this with esbuild by creating a
tsconfig.json
orjsconfig.json
file that looks something like this: