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.

How to alias externaled module path?

See original GitHub issue

There’s a problem for me to do SSR building, it’s our framework export alias module, and use resolve.alias to alias the module , like React, we use

import React from 'bar/lib/sdk/react';

// not use
import React from 'react';

so now, I only add bar/lib/sdk/react into whiteList, but it’s unconscionable to bundle all React library.

How could I solve the problem?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
daniel-nagycommented, Jan 18, 2021

I think they had a resolve alias for react but Webpack was requiring react as an external dependency instead of their aliased module. I just ran into a similar issue with lodash-es, which doesn’t work in a node runtime. I tried to rewrite the import to lodash

resolve: {
  alias: {
    "lodash-es": "lodash"
  }
}

but Webpack was still requiring lodash-es. I was able to work around it with the following.

externals: [
  nodeExternals({ allowlist: ["lodash-es"] }),
  { "lodash-es": "commonjs lodash" }
]

Note that the resolve alias is not necessary in this case. This seems to be an issue with Webpack but it might be nice to add an API to this module to rewrite external modules.

1reaction
Pines-Chengcommented, May 29, 2020

@ycjcl868 same question, looks like that you had avoided this by giving up external。

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module Resolution or Import Alias: The Final Guide - Raul Melo
Module resolution or import alias is a way we can emulate the same way we import node_modules but with our internal code. We...
Read more >
Path aliases with TypeScript in Node.js
Step 2: Install module-alias package ... Note that 'dist' is the folder where the compiled JS files are located. Last but not least...
Read more >
How to alias external module path when in ssr?
In other words, I config the resolve.alias = { 'bar/sdk/react': dirname(join(process.cwd(), 'node_modules', 'react')) } both in client and ...
Read more >
Absolute Imports and Module Path Aliases
Configure module path aliases that allow you to remap certain import paths.
Read more >
How to have path alias in Node.js
Create aliases of directories and register custom module paths in NodeJS using module-alias. Let's first install module-alias. Syntax: npm ...
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