question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't use lodash with this library

See original GitHub issue

Type 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:closed
  • Created 6 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
DavidParks8commented, Dec 5, 2017

You need to add the correct lodash external to your ngpackagr config. Alternarively, you can use ‘lodash-es’ and the build should succeed.

2reactions
tommuellercommented, Jan 24, 2018

@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:

"externals": {
    "lodash": "./node_modules/lodash/index.js"
}

Cheers, Tom

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found