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.

Should error / warn when using import or require

See original GitHub issue

These days there are lots of ways to pull in a lodash function. I would expect each of these to generate errors.

import forEach from 'lodash/forEach'
import whatever from 'lodash/forEach'

import { forEach } from 'lodash'
import { forEach as whatever } from 'lodash'

import forEach from 'lodash.foreach'
import whatever from 'lodash.foreach'

const forEach = require('lodash/forEach')
const whatever = require('lodash/forEach')

const { forEach } = require('lodash')
const { forEach: whatever } = require('lodash')

const forEach = require('lodash.foreach')
const whatever = require('lodash.foreach')

I was surprised that this wasn’t generating errors in my project. Did I miss something?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
stevemaocommented, Aug 22, 2017

@heygrady Could you send us a PR?

0reactions
fabiomcostacommented, May 25, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning when trying to require a module which is not installed ...
It seems like this is a common issue in webpack. According to the configuration docs, you can use the flag module: { exprContextCritical: ......
Read more >
warnings — Warning control — Python 3.11.1 documentation
Python programmers issue warnings by calling the warn() function defined in this module. (C programmers use PyErr_WarnEx() ; see · Warning messages are...
Read more >
Must use import to load ES Module / require() of ES ... - GitHub
I have suddenly started getting the following error: $ npm test > geodesy@2.2.0 test /home/travis/build/chrisveness/geodesy > mocha --exit ...
Read more >
Using import and require in the same file - Node JS - YouTube
Found solution here: https://www.kindacode.com/article/node-js-how-to- use - import -and- require -in-the-same-file/
Read more >
5.2. Warnings and sanity-checking - downloads for Haskell.org
This warning allows to detect such uses of * before the actual breaking change takes place. The recommended fix is to replace *...
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