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.

Absolute node_modules paths are not getting resolved during SSR

See original GitHub issue

💬 Questions and Help

I am not sure if this issue is similar to #293. I am importing a component from node_modules. const ComponentName = loadable(() => import("@nodeModuleName/[path-to-component]") );

This import runs on client side. (i.e., when I run using { ssr: false }, the component gets load). But it does not load on server side. Throws error Cannot find module '/Users/[my-project]/@nodeModuleName/[path-to-component]'

the import gets resolved to

var ComponentName = (0, _component.default)({
  chunkName: function chunkName() {
    return "ComponentName";
  },
  isReady: function isReady(props) {
    if (typeof __webpack_modules__ !== 'undefined') {
      return !!__webpack_modules__[this.resolve(props)];
    }

    return false;
  },
  requireAsync: function requireAsync() {
    return import(
    "@nodeModuleName/[path-to-component]");
  },
  requireSync: function requireSync(props) {
    var id = this.resolve(props);

    if (typeof __webpack_require__ !== 'undefined') {
      return __webpack_require__(id);
    }

    return eval('module.require')(id);
  },
  resolve: function resolve() {
    if (require.resolveWeak) {
      return require.resolveWeak("@nodeModuleName/[path-to-component]");
    }

    return require('path').resolve(__dirname, "@nodeModuleName/[path-to-component]");
  }
});

Issue #293 mentioned that he is not using webpack but I do use webpack, then also getting error. Any help is appreciated

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
gregbergecommented, Apr 9, 2019

I think the problem is here:

return require('path').resolve(__dirname, "@nodeModuleName/[path-to-component]");

We should replace it by:

return eval('require.resolve')("@nodeModuleName/[path-to-component]");

What do you think @theKashey?

0reactions
fatemabcommented, Apr 11, 2019

@neoziro Thank you so much for such a prompt release!

Read more comments on GitHub >

github_iconTop Results From Across the Web

import is not working nodeJs application React SSR
We name it webpack.config.js in the root of the app. const path=require("path") module ...
Read more >
Advanced Features: Absolute Imports and Module Path Aliases
Configure module path aliases that allow you to remap certain import paths. ... Note: jsconfig.json can be used when you don't use TypeScript....
Read more >
Static Asset Handling - Vite
Importing a static asset will return the resolved public URL when it is served: ... be either using absolute public paths (based on...
Read more >
Node.js path.resolve() Method - GeeksforGeeks
The path.resolve() method is used to resolve a sequence of path-segments to an absolute path. It works by processing the sequence of paths...
Read more >
css-loader | webpack - JS.ORG
If set to false , css-loader will not parse any paths specified in url or ... To import assets from a node_modules path...
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