简体   繁体   English

带有 Typescript 和 Webpack 模块错误的 Lodash-es

[英]Lodash-es with Typescript and Webpack module error

I want to use lodash-es to be able to import only the functions I need, but I get an error.我想使用 lodash-es 来只导入我需要的功能,但是我得到了一个错误。

import { camelCase } from "lodash-es";
//...
console.log(camelCase('Foo'));

Error:错误:

Module not found: Error: Can't resolve 'lodash-es' in '/Users/...找不到模块:错误:无法解析 '/Users/... 中的 'lodash-es'

Browser console error浏览器控制台错误

Uncaught Error: Cannot find module 'lodash-es' at webpackMissingModule..未捕获的错误:在 webpackMissingModule.. 找不到模块“lodash-es”

My package.json我的 package.json

...
"devDependencies": {
"@types/lodash": "^4.14.178",
"@types/lodash-es": "^4.17.5",

Using normal lodash I have no problems, but the library is too big for my purpose使用普通的 lodash 我没有问题,但是这个库对我来说太大了

You also need lodash-es (or lodash ) in your dependecies.您还需要lodash-es (或lodash )在您的依赖项中。 You can import individual functions like this:您可以像这样导入单个函数:

import camelCase from "lodash-es/camelCase";

to keep the bundle size low.以保持较小的包大小。 @types/* packages are just type definitions. @types/*包只是类型定义。

Also, some functions can be installed isolated from the rest: https://www.npmjs.com/package/lodash.camelcase此外,一些功能可以与 rest 隔离安装: https://www.npmjs.com/package/lodash.camelcase

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM