D
D
Desire23042019-03-05 00:37:40
JavaScript
Desire2304, 2019-03-05 00:37:40

What's wrong with the NPM library?

A very strange problem.
There is a library of components (Angular, TypeScript), uploaded and available on NPM. After the last update and the publication of the library on NPM (a very minor update, in fact, two lines inside the component that do not make any difference) stopped working.
I update (just on a local project, npm install ), run it, it displays in the console:

node_modules/<lib name>/dist/button/button.d.ts(2,47): error TS2307: Cannot find module '../core'.

And there are several similar errors. I look, how it does not find the module. I've already looked at everything, I go to the folder with either, and there the "core" folder is stupidly missing, and, of course, the module is not detected and nothing works. That is, it is in the source code and everything works -> I publish it on NPM -> I install it on another project - the "core" folder disappears.
I think maybe during the compilation of TypeScript -> JavaScript (this is done before uploading to NPM) something is wrong? Looked - in the compiled version the "core" directory is present and everything works. I played around with the compilation settings, chose different "module code generation" (commonJS / etc) - everything is the same.
I think maybe the "core" directory got ignored? Neither .npmignore nor .gitignore (although git has nothing to do with it) has nothing of the kind.
Googling doesn't find anything.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Desire2304, 2019-03-21
@Desire2304

In short, I solved the problem. Added the files field to package.json:

"files": [
    "dist/"
  ]

In dist, I have a compiled version of the library, i.e. directories button, core (which disappeared after npm install), and others. Those. this way we tell npm that in this package we want to force the inclusion of dist/ with all its contents. Why core/ disappeared - I did not understand. Looks like npm has some kind of tree-shaker analogue that I don't know about.

M
Maxim Vasiliev, 2019-03-16
@qmax

Deep under the hood, Angular uses webpack, which is very fond of calculating dependencies and optimizing unused modules.
Most likely, he failed to install the dependency between button and core.
Try specifying the full path from the project root there instead of `..`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question