My Current Setup
I have recently developed and published an npm package in typescript. This package contains references to font files located within a folder named public/fonts
internally.
Now, I am in the process of installing this package into an Angular application.
Upon installation, the file structure within the node_modules
directory looks like this:
node_modules/
mypackage/
dist/
index.d.ts
index.js
public/
fonts/
LICENSE
README.md
package.json
tsconfig.json
In the index.js
file, I reference the font files as follows:
'Roboto': {
normal: 'public/fonts/Roboto-Regular.ttf',
bold: 'public/fonts/Roboto-Bold.ttf',
italics: 'public/fonts/Roboto-Italic.ttf',
bolditalics: 'public/fonts/Roboto-BoldItalic.ttf'
}
Initially, during the package development stage, there were no errors reported.
Current Issue
However, after successfully installing and importing the package into my application, I encountered the following error while using it:
Error: ENOENT: no such file or directory, open 'public/fonts/Roboto-Bold.ttf'
Observation
I noticed that if I place the public folder at the root level of the application utilizing the package, everything works as expected. It seems that the package is searching for public/fonts/
at the application's root level rather than within the package itself.
Do you have any suggestions on how to reference these files from within the package without encountering errors during development?
Additionally, I also encountered another error related to my package's tsconfig.json
:
[ts] No inputs were found in ...../mypackage/tsconfig.json. Specified 'include' paths were [**/*] and 'exclude' paths were [./dist]
.
To resolve this issue, I had to add a blank .ts file at the root of the package. Is there a better alternative solution available?
Edit (including my package's tsconfig.json
)
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": true,
"outDir": "./dist",
"strict": true,
"noImplicitAny": false,
"lib": [
"es2015"
]
}
}