swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

js-yaml dependency breaking webpack build

Open ALEX-TING opened this issue 7 years ago • 2 comments

When building with webpack, esprima cannot be resolved in js-yaml module, causing the build to break with the following error messages:

WARNING in ./node_modules/js-yaml/lib/js-yaml/type/js/function.js
Module not found: Error: Can't resolve 'esprima' in '/Users/alexcting/Desktop/Appcues/react.appcues.com/node_modules/js-yaml/lib/js-yaml/type/js'
 @ ./node_modules/js-yaml/lib/js-yaml/type/js/function.js
 @ ./node_modules/js-yaml/lib/js-yaml/schema/default_full.js
 @ ./node_modules/js-yaml/lib/js-yaml.js
 @ ./node_modules/js-yaml/index.js
 @ ./node_modules/json-schema-ref-parser/lib/util/yaml.js
 @ ./node_modules/json-schema-ref-parser/lib/index.js
 @ ./node_modules/swagger-parser/lib/index.js
 @ ./src/utils/stubMatcher.js
 @ ./src/utils/stubFetch.js
 @ ./src/helpers/mobile/index.js
 @ ./src/sagas/mobile/index.js
 @ ./src/sagas/index.js
 @ ./src/store/configureStore.js
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?https://localhost:3007 (webpack)/hot/dev-server.js react-hot-loader/patch webpack-dev-server/client?http://localhost:3007 ./src/main

and subsequently,

ERROR in ./node_modules/z-schema/src/Utils.js
Module not found: Error: Can't resolve 'core-js/es/symbol' in '/Users/alexcting/Desktop/Appcues/react.appcues.com/node_modules/z-schema/src'
 @ ./node_modules/z-schema/src/Utils.js 3:0-28
 @ ./node_modules/z-schema/src/ZSchema.js
 @ ./node_modules/swagger-parser/lib/validators/schema.js
 @ ./node_modules/swagger-parser/lib/index.js
 @ ./src/utils/stubMatcher.js
 @ ./src/utils/stubFetch.js
 @ ./src/helpers/mobile/index.js
 @ ./src/sagas/mobile/index.js
 @ ./src/sagas/index.js
 @ ./src/store/configureStore.js
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?https://localhost:3007 (webpack)/hot/dev-server.js react-hot-loader/patch webpack-dev-server/client?http://localhost:3007 ./src/main

Looks like esprima is excluded from being bundled for the browser on purpose (see here)? Any solution or workaround for this?

ALEX-TING avatar Aug 28 '19 20:08 ALEX-TING

Webpack and other bundling tools allow you to override how specific modules are resolved and replace/ignore them. So you can configure webpack to specifically ignore esprima, or replace it with a substitute.

JamesMessinger avatar Aug 28 '19 20:08 JamesMessinger

for ppl coming here from G here's an actual helpful comment on how to resolve this https://github.com/sindresorhus/file-type/issues/417#issuecomment-734957077

dcsan avatar Nov 14 '21 03:11 dcsan