Can't use lodash with this library
See original GitHub issueType of Issue
[x] Bug Report
[ ] Feature Request
Description
Rollup throws a build error when compiling to FESM15
Error thrown:
Running ngc
Compiling to FESM15
BUILD ERROR
'forEach' is not exported by node_modules/lodash/lodash.js
Error: 'forEach' is not exported by node_modules/lodash/lodash.js
at error (/home/talleane/Documents/play-utility/node_modules/rollup/dist/rollup.js:185:14)
at Module.error (/home/talleane/Documents/play-utility/node_modules/rollup/dist/rollup.js:16526:3)
at Module.trace (/home/talleane/Documents/play-utility/node_modules/rollup/dist/rollup.js:16623:10)
at ModuleScope.findVariable (/home/talleane/Documents/play-utility/node_modules/rollup/dist/rollup.js:13965:22)
at Node._bindVariableIfMissing (/home/talleane/Documents/play-utility/node_modules/rollup/dist/rollup.js:12626:31)
at Node.bindNode (/home/talleane/Documents/play-utility/node_modules/rollup/dist/rollup.js:12621:8)
at Node.bind (/home/talleane/Documents/play-utility/node_modules/rollup/dist/rollup.js:11005:8)
at eachChild.child (/home/talleane/Documents/play-utility/node_modules/rollup/dist/rollup.js:11024:34)
at value.forEach.child (/home/talleane/Documents/play-utility/node_modules/rollup/dist/rollup.js:11039:38)
at Array.forEach (<anonymous>)
How To Reproduce
first install lodash
npm install lodash
In your code
import {forEach} from "lodash";
console.log(forEach);
Expected Behaviour
Expected that no error is thrown and a packge is generated
Version Information
ng-packagr: v1.6.0
node: v8.6.0
@angular: v4.2.4
rxjs: 5.4.2
zone.js: 0.8.14
lodash: 4.17.4
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
Correct way to import lodash - Stack Overflow
import has from 'lodash/has'; is better because lodash holds all it's functions in a single file, so rather than import the whole 'lodash' ......
Read more >The Correct Way to Import Lodash Libraries: A Benchmark
Importing Lodash libraries doesn't need to be daunting. Get insights into the top three ways to import Lodash functions.
Read more >How to use Lodash with Vue | SamanthaMing.com
Learn how to install Lodash and use it with Vue. ... How to use Lodash with Vue. Lodash is a JavaScript library that...
Read more >How is possible to use a library as lodash in function node?
I want to use lodash into function module. But I was reading the documentation and it seems that I need to create a...
Read more >lightning web components - How to Import lodash into org?
@OleksandrBerehovskyi That's a cool library, you can import individual features, but if I were to use lodash, I'd import it in a way...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You need to add the correct lodash external to your ngpackagr config. Alternarively, you can use ‘lodash-es’ and the build should succeed.
@Itrulia I was a bit puzzled about this myself, as it isn’t very well documented so far. I did finally manage to solve by adding this to my ng-package.json:
Cheers, Tom