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.

Getting SyntaxError: Unexpected identifier

See original GitHub issue

🐛 Bug report

Current Behavior

When I am building on my server, I am getting this error

/var/www/lite-2/valkyrie/node_modules/lodash-es/clone.js:1
(function (exports, require, module, __filename, __dirname) { import baseClone from './_baseClone.js';
                                                                     ^^^^^^^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:80:7)
    at createScript (vm.js:274:10)
    at Object.runInThisContext (vm.js:326:10)
    at Module._compile (internal/modules/cjs/loader.js:664:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
/var/www/lite-2/valkyrie/node_modules/lodash-es/clone.js:1
(function (exports, require, module, __filename, __dirname) { import baseClone from './_baseClone.js';

Upon looking I found that formik is the only npm module, that is using lodash-es behind the scene.

Expected behavior

The build should go seamless.

Reproducible example

Suggested solution(s)

By using lodash instead of lodash-es

Additional context

Your environment

Software Version(s)
Formik 1.5.8
React 16.8.1
TypeScript na
Browser na
npm/Yarn 6.4.1/1.17.3
Operating System Ubuntu 14.04.5 LTS

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
Shaun2D2commented, Sep 9, 2019

@deeksha-agarwal just curious why this issue was closed. Do you know why Formik is using lodash-es at all? It seems like we should be able to get away with just using lodash… I’m running into a situation where i’m importing both lodash (for my project) and then another copy of lodash-es so I get double the size.

would be happy to dive in and see if I can submit a PR to remove it and just use core lodash.

cc: @jaredpalmer

2reactions
Shaun2D2commented, Nov 20, 2019

@nikitaindik after doing some research on this, it appears Formik uses a TypeScript development tool called tsdx. This appears to reference lodash in their docs.

It looks like this tool requires the inclusion of lodash-es. This is supposed to be to avoiding bloating the bundle but I’m not sure this is actually getting accomplished based off our bundle analyzer results as both lodash and lodash-es were getting included into the Formik bundle.

Maybe I’m missing something here, @jaredpalmer may have some thoughts on this? Seem to specific to tsdx and not Formik so probably can’t fix this here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Solve The Unexpected Identifier Error in JavaScript
It will look through your code and if it detects any errors it will tell you specifically where that error exists.
Read more >
A Common Cause of "Uncaught syntax error - Techstacker
A Common Cause of "Uncaught syntax error: unexpected identifier" in JavaScript ... One of the most common reasons is that you're trying to...
Read more >
Unexpected Identifier in Chrome's Javascript console
I got SyntaxError: Unexpected identifier error, for invalid order between async and static, static must come first.
Read more >
How to Fix "Uncaught SyntaxError: Unexpected identifier" in ...
In this post, we looked at what causes the Uncaught SyntaxError: Unexpected identifier error and how to fix it. In most cases, it...
Read more >
SyntaxError: Unexpected identifier - Codecademy
SyntaxError : Unexpected identifier ... I'm trying to create a program which asks the user what they're favorite Big Ten team is, checks...
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