7

I am importing a third-party module which imports another module:

import fetch from "cross-fetch";

I would like to tell Webpack to ignore/remove this import because the variable fetch already exists in global namespace. Is that possible?

6
  • So, are you trying to tell Webpack not to throw an error? Commented Jan 1, 2020 at 16:06
  • I just want to skip this import. fetch already exists in global namespace provided by the serverless enviroment I use. I want the third-party module NOT to import cross-fetch and instead use the already existent global variable. Commented Jan 1, 2020 at 16:07
  • Does this answer your question? How can I make webpack skip a require Commented Jan 1, 2020 at 16:10
  • I tried to use IgnorePlugin but then the import statement is bundled and throws an exception. The import statement should be removed instead. Commented Jan 1, 2020 at 16:12
  • Did you try the highest voted answer's solution?: const myCustomModule = eval('require')(myCustomPath) Commented Jan 1, 2020 at 16:13

1 Answer 1

5

You can specify that some module is in the global env with externals.

// webpack.config.js module.exports = { //... externals: { 'cross-fetch': 'fetch' } }; 
Sign up to request clarification or add additional context in comments.

1 Comment

wouldn't that should be 'cross-fetch': 'fetch' instead. The left part match the import and the right part how to handle it and replace the import ???

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.