Closed andyjessop closed 10 months ago
You'll need a tsconfig that is able to resolve package exports, for example a moduleResolution
of bundler
or node16
. You can find a working example here: https://github.com/pwa-builder/pwa-starter
Unfortunately that brings its own issues. I would have to convert the whole project to type: module
and then use the .js
extension for all relative imports.
I would have to convert the whole project to type: module
I dont think thats true, thats not the case in pwa-builder either
Ah actually, Bundler
does work fine (but Node16
gives this error:
Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean ...
Thanks for your help. I'll do some reading on Bundler
.
It might be worth adding a section about this in the README.
It might be worth adding a section about this in the README.
Yeah, thats a good point. Ill try to update the docs about this soon.
I'll close this issue now, please feel free to reopen if you run into any other problems :)
@thepassle I tried to PR changes to the docs, but I don't have permission:
Here is the section I tried to add to the README:
## Using `@thepassle/app-tools` with TypeScript
In order for your project to see the provided type declaration files, you may need to modify your `tsconfig.json`. Two primary configurations can resolve these issues:
1. **`moduleResolution: node16` or `moduleResolution: nodenext**:
- Modern versions of Node.js (v12 and later) support ECMAScript imports and CommonJS `require`, resolving them using different algorithms.
- **This approach requires explicit `.js` file extensions in TypeScript imports.**
- Suitable for projects aligned with modern Node.js module resolution strategies.
2. **Using `moduleResolution: bundler`**:
- Ideal for projects utilising bundlers.
- Supports `package.json` "imports" and "exports" without requiring file extensions on relative paths.
- Note: `bundler` does not support resolution of `require` calls in TypeScript files.
### Further Reading
For more detailed information on `moduleResolution` configurations, please refer to the [TypeScript documentation](https://www.typescriptlang.org/tsconfig#moduleResolution).
Cool, thanks! Ill add this to the readme tomorrow
I've just installed the router with
npm i -S @thepassle/app-tools
. I copy/pasted the example from the router readme and am getting the following TS errors: