I'm trying to do something very similar to the jquery path example in the documentation, but TS keeps throwing TS2307
(webpack compiles fine):
"compilerOptions": { "baseUrl": "./src", "paths": { "@client": [ "client", ], "@suir": [ "../node_modules/semantic-ui-react/dist/commonjs", // not working ], }, // … }, "include": [ "*.d.ts", "client/**/*", "../node_modules/semantic-ui-react", // is this necessary? ],
Changing baseUrl
to "."
and updating includes
and paths
makes no difference (@client
continues to work and @suir
continues to not work).
Changing "@suir"
to "@suir/"
or "@suir/*"
(and appending /*
to its value) also makes no difference.
The reason I'm doing this is to simplify my imports (I'm specifying them explicitly instead of pulling named exports from the bundle in order to reduce my vendor bundle size—saves about 1 MB):
import Button from 'semantic-ui-react/dist/commonjs/elements/Button'; // works import Button from '@suir/elements/Button'; // not found
Running tsc locally will compile the closest project defined by a tsconfig. json , you can compile a set of TypeScript files by passing in a glob of files you want.
The tsconfig. json file specifies the root files and the compiler options required to compile the project. JavaScript projects can use a jsconfig. json file instead, which acts almost the same but has some JavaScript-related compiler flags enabled by default.
SWC support is built-in via the --swc flag or "swc": true tsconfig option. SWC is a TypeScript-compatible transpiler implemented in Rust. This makes it an order of magnitude faster than vanilla transpileOnly . To use it, first install @swc/core or @swc/wasm .
I have no idea why this is now working on the eleventh time I tried (yet didn't the first 10), but the /*
seems to be the secret sauce, and the example in the docs is apparently pointing to a specific file (and the file extension is omitted).
{ "compilerOptions": { "baseUrl": "./src", // setting a value for baseUrl is required "moduleResolution": "node", // was not set before, but is the default "paths": { "@client/*": [ "client/*", ], "@suir/*": [ // notice the `/*` at the end "../node_modules/semantic-ui-react/dist/commonjs/*", // notice the `/*` ], }, // … }, "include": [ "./src/client/**/*", ], }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With