admin管理员组文章数量:1420205
So I forked a package in the git. Made my changes. Then in my terminal
npm install --save git+.js.git
And then I try to import the package in my code as this
import DDP from 'ddp.js'
But webpack gives me this error
ERROR in ./main.js
Module not found: Error: Can't resolve 'ddp.js' in '/Users/hayksafaryan/projects/b2cEmbedLib'
@ ./main.js 23:11-28
@ multi (webpack)-dev-server/client?http://localhost:8080 babel-polyfill ./main.js
webpack: Failed to pile.
However webpack works fine if I install the package from npm. I import the package as in the docs, however maybe there is some other way for git installed packages?
So I forked a package in the git. Made my changes. Then in my terminal
npm install --save git+https://github./hayk94/ddp.js.git
And then I try to import the package in my code as this
import DDP from 'ddp.js'
But webpack gives me this error
ERROR in ./main.js
Module not found: Error: Can't resolve 'ddp.js' in '/Users/hayksafaryan/projects/b2cEmbedLib'
@ ./main.js 23:11-28
@ multi (webpack)-dev-server/client?http://localhost:8080 babel-polyfill ./main.js
webpack: Failed to pile.
However webpack works fine if I install the package from npm. I import the package as in the docs, however maybe there is some other way for git installed packages?
Share Improve this question edited Oct 10, 2017 at 10:13 Hayk Safaryan asked Oct 10, 2017 at 8:14 Hayk SafaryanHayk Safaryan 2,0564 gold badges33 silver badges55 bronze badges1 Answer
Reset to default 7The entry point of the package is lib/ddp.js
, but that file doesn't exist in the repository. It is very mon that libraries build their libraries before publishing to npm, so that they can use newer JavaScript features but still provide support for older versions that don't support them. This is done with the prepublish
hook, which is automatically run before the package is published (when you run npm publish
). With that, the built files don't end up in the repository, as it would mainly clutter up your mits. Some people decide to check them in so they can use it directly from there, which has bee quite rare because these use-cases are generally covered by services like Unpkg.
You have several possibilities to use it from a git repository.
- Check in the built files.
- Build the files after installing. Either manually or with a
postinstall
hook. (not remended) - Change the entry point to
src/ddp.js
. If you need to transpile the files, this isn't a valid option, even though you could theoretically whitelist the package in your webpack config, so it gets transpiled (assuming you were excludingnode_modules
from being transpiled). - Publish the package to npm under your namespace (
@yourusername/ddp.js
) and use that. For details see Working with scoped packages.
本文标签: javascriptWebpack can39t import package installed from gitStack Overflow
版权声明:本文标题:javascript - Webpack can't import package installed from git - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745324772a2653538.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论