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.

[Resolved] SSR not possible due to `lodash-es`

See original GitHub issue

Hi,

After having successfully used this package in a standard react setting, I was trying to port that code to next.js to enable some Server-Side rendering, when the following error was thrown:

[...]/node_modules/lodash-es/isNumber.js:1
import baseGetTag from './_baseGetTag.js';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Module._compile (internal/modules/cjs/loader.js:895:18)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Module.require (internal/modules/cjs/loader.js:852:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> ([...]/node_modules/react-d3-speedometer/dist/core/util/index.js:1:616)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)

It appears from the Changelog that normal lodash was replaced not that long ago, without significant changes since, so I was able to downgrade to 0.10.1 without much issue but thought I’d post a shout as an FYI, for future design consideration, or other people running into this.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
warmansugandacommented, Nov 6, 2021

hi @palerdot i’ve other solution for next.js, it works for me! Reference: https://nextjs.org/docs/advanced-features/dynamic-import#with-no-ssr

import React from 'react';
import dynamic from 'next/dynamic';

const ReactSpeedometer = dynamic(
  () => import('react-d3-speedometer'),
  { ssr: false },
);

function Speedometer() {
  return (
    <div>
      <ReactSpeedometer />
    </div>
  );
}

export default Speedometer;
0reactions
palerdotcommented, Nov 7, 2021

@warmansuganda Thank you. I will link this issue in the FAQ so that people can find the solution you suggested.

You can also raise a PR for this if you are interested.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SSR Externals False Positive on Windows #2393 - vitejs/vite
The path requireEntry comes from require.resolve which is not normalized. ... This leads to a false positive, thinking the package has a cjs...
Read more >
Module not found: Error: Can't resolve 'cypress/types/lodash
I am running my first test in Cypress from VS IDE and Cypress was working while until I encountered the error below ...
Read more >
Server-side rendering (SSR) - Inertia.js
SSR is not yet ready for the Svelte adapter. However, it's something we're actively working on adding. How it works. When Inertia detects...
Read more >
How to Configure SSG and SSR on Nuxt.js - Mad Devs
Since nuxt has several modes of operation, not all plugins can be plugged directly into components. This is due to the fact that...
Read more >
Node.js Server Side Rendering (SSR) using EJS
Server-side rendering (SSR) is a popular technique for rendering a normally client-side only single page app (SPA) on the server and then ...
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