jsedn icon indicating copy to clipboard operation
jsedn copied to clipboard

require fails in webpack due to node imports

Open acthp opened this issue 6 years ago • 2 comments

Module not found: Error: Can't resolve 'fs' in '/home/brian/tmp/XenaGoWidget/node_modules/jsedn/lib'
 @ ./node_modules/jsedn/lib/reader.js 275:9-22
 @ ./node_modules/jsedn/index.js
 @ ./src/XenaGoApp.js
 @ ./demo/src/index.js
 @ multi ./node_modules/nwb/polyfills.js (webpack)-dev-server/client?/ (webpack)/hot/only-dev-server.js ./demo/src/index.js
Module not found: Error: Can't resolve 'type' in '/home/brian/tmp/XenaGoWidget/node_modules/jsedn/lib'
 @ ./node_modules/jsedn/lib/type.js 3:105-120
 @ ./node_modules/jsedn/lib/reader.js
 @ ./node_modules/jsedn/index.js
 @ ./src/XenaGoApp.js
 @ ./demo/src/index.js
 @ multi ./node_modules/nwb/polyfills.js (webpack)-dev-server/client?/ (webpack)/hot/only-dev-server.js ./demo/src/index.js

acthp avatar Mar 14 '18 16:03 acthp

has anyone found a solution for this?

Malabarba avatar Sep 07 '18 23:09 Malabarba

So, I seem to have just gotten this working for me, though I'm not totally happy with the solution. The root of the problem seems to be that type-component is in the dependencies, but type isn't. When webpack is going through looking for it's require statements, it's finding a require for both. It doesn't care that we only ever use one or the other, it's going to try to bundle them both anyways. The problem is that type can't be found in that context. I tried having type be a dependency of the parent project, but it didn't seem to care much.

My work-around was to alias "type" to "type-component" in my webpack config. This means type-component probably gets bundled twice... but it bundles. However, it could have strange effects in other dependencies that may also require "type"

resolve: { alias: { type: 'type-component' } },

npfitz avatar Mar 17 '19 23:03 npfitz