plasticine / inject-loader

💉📦 A Webpack loader for injecting code into modules via their dependencies.
https://www.npmjs.com/package/inject-loader
MIT License
484 stars 47 forks source link

Calling require() with dynamically formed paths leads to runtime issue with webpack #59

Closed andreventuravale closed 5 years ago

andreventuravale commented 6 years ago

Calling require() with dynamically formed paths leads to runtime issue with webpack:

const module = require(`\${ENTRY_POINT}\any-module.js`);

Throws the following issue with webpack 3 at runtime:

 Uncaught Error: Module build failed: TypeError: Property value expected type of string but got null
      at Object.validate (/Users/andrevale/workspace/canvas/node_modules/babel-types/lib/definitions/index.js:161:13)
      at validate (/Users/andrevale/workspace/canvas/node_modules/babel-types/lib/index.js:505:9)
      at Object.builder (/Users/andrevale/workspace/canvas/node_modules/babel-types/lib/index.js:466:7)
      at /Users/andrevale/workspace/canvas/node_modules/inject-loader/dist/index.js:1:2733
      at CallExpression (/Users/andrevale/workspace/canvas/node_modules/inject-loader/dist/index.js:1:2853)
      at NodePath._call (/Users/andrevale/workspace/canvas/node_modules/babel-traverse/lib/path/context.js:76:18)
      at NodePath.call (/Users/andrevale/workspace/canvas/node_modules/babel-traverse/lib/path/context.js:48:17)
      at NodePath.visit (/Users/andrevale/workspace/canvas/node_modules/babel-traverse/lib/path/context.js:105:12)
      at TraversalContext.visitQueue (/Users/andrevale/workspace/canvas/node_modules/babel-traverse/lib/context.js:150:16)
      at TraversalContext.visitSingle (/Users/andrevale/workspace/canvas/node_modules/babel-traverse/lib/context.js:108:19)
      at TraversalContext.visit (/Users/andrevale/workspace/canvas/node_modules/babel-traverse/lib/context.js:192:19)
      at Function.traverse.node (/Users/andrevale/workspace/canvas/node_modules/babel-traverse/lib/index.js:114:17)
      at NodePath.visit (/Users/andrevale/workspace/canvas/node_modules/babel-traverse/lib/path/context.js:115:19)
      at TraversalContext.visitQueue (/Users/andrevale/workspace/canvas/node_modules/babel-traverse/lib/context.js:150:16)
      at TraversalContext.visitMultiple (/Users/andrevale/workspace/canvas/node_modules/babel-traverse/lib/context.js:103:17)
      at TraversalContext.visit (/Users/andrevale/workspace/canvas/node_modules/babel-traverse/lib/context.js:190:19)