I have tried build my own lib to use on my Vue project typescript, but I can’t import the lib after install them via npm install git+ssh://[email protected]:companyName/internal-lib.git#master
here is my internal-lib
package.json
{
"name": "@companyName/internal-lib",
"private": true,
"version": "1.0.1",
"description": "",
"scripts": {
"build": "parcel build"
},
"main": "dist/main.js",
"type": "module",
"css": "dist/style.css",
"module": "dist/module.js",
"types": "dist/types.d.ts",
"targets": {
"main": {
"source": "src/main.ts"
},
"css": {
"source": "src/style.css"
}
},
"author": "",
"license": "MIT",
"dependencies": {
"dayjs": "^1.11.7"
},
"devDependencies": {
"@parcel/transformer-typescript-tsc": "^2.8.3",
"parcel": "^2.8.3",
"typescript": "^5.0.4"
}
}
and here is my src/main.ts
import dayjs from 'dayjs'
class UtilDatetime {
/**
*
* @param date {string}
* @param format { string}
* @return {*|string}
*/
static formatDate(date: string, format = 'DD MMMM YYYY, HH:mm Z'): string {
return date ? dayjs(date).format(format) : '-'
}
}
export { UtilDatetime }
parcel js doesn’t build dist/types.d.ts
here, I don’t know why
I build them via parcel build
, then after I install that lib above and import into my Vue project
import UtilDateTime from '@companyName/internal-lib'
my IDE said
TS7016: Could not find a declaration file for module '@companyName/internal-lib'. '/Users/myNameHere/Documents/contribute/companyName/fe/cms-thing/node_modules/@companyName/internal-lib/dist/main.js'
implicitly has an 'any' type.
Try `npm i --save-dev @types/companyName__internal-lib`
if it exists or add a new declaration (.d.ts) file containing `declare module '@companyName/internal-lib';`
but when I import like this
import { UtilDatetime } from '@companyName/internal-lib/src/main'
is that something wrong when I build the library?
why I can’t import only from @companyName/internal-lib
instead I need to import full path ?