Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module not found: Error: Cannot resolve module 'fs' #27

Closed
rowino opened this issue Sep 6, 2016 · 7 comments
Closed

Module not found: Error: Cannot resolve module 'fs' #27

rowino opened this issue Sep 6, 2016 · 7 comments

Comments

@rowino
Copy link

rowino commented Sep 6, 2016

I am using the babel generator boilerplate for a library I am building. I added this library and imported it into my project. Now when I run gulp build I get the following error. Any assistance would be highly appreciated.

stream.js:74
      throw er; // Unhandled stream error in pipe.
      ^
Error: ./~/json-schema-ref-parser/lib/resolvers/file.js
Module not found: Error: Cannot resolve module 'fs' in /home/raphael/work/projects/packages/json-schema-form-generator/node_modules/json-schema-ref-parser/lib/resolvers
resolve module fs in /home/raphael/work/projects/packages/json-schema-form-generator/node_modules/json-schema-ref-parser/lib/resolvers
  looking for modules in /home/raphael/work/projects/packages/json-schema-form-generator/node_modules
    /home/raphael/work/projects/packages/json-schema-form-generator/node_modules/fs doesn't exist (module as directory)
    resolve 'file' fs in /home/raphael/work/projects/packages/json-schema-form-generator/node_modules
      resolve file
        /home/raphael/work/projects/packages/json-schema-form-generator/node_modules/fs doesn't exist
        /home/raphael/work/projects/packages/json-schema-form-generator/node_modules/fs.webpack.js doesn't exist
        /home/raphael/work/projects/packages/json-schema-form-generator/node_modules/fs.web.js doesn't exist
        /home/raphael/work/projects/packages/json-schema-form-generator/node_modules/fs.js doesn't exist
        /home/raphael/work/projects/packages/json-schema-form-generator/node_modules/fs.json doesn't exist
[/home/raphael/work/projects/packages/json-schema-form-generator/node_modules/fs]
[/home/raphael/work/projects/packages/json-schema-form-generator/node_modules/fs]
[/home/raphael/work/projects/packages/json-schema-form-generator/node_modules/fs.webpack.js]
[/home/raphael/work/projects/packages/json-schema-form-generator/node_modules/fs.web.js]
[/home/raphael/work/projects/packages/json-schema-form-generator/node_modules/fs.js]
[/home/raphael/work/projects/packages/json-schema-form-generator/node_modules/fs.json]
 @ ./~/json-schema-ref-parser/lib/resolvers/file.js 2:14-27
@JamesMessinger
Copy link
Member

It looks like you're using webpack, and something in your config is causing it to load the Node.js version of JSON Schema Ref Parser rather than the browser version.

@majuric
Copy link

majuric commented Oct 18, 2016

I had the same problem. Solved it by adding the alias in webpack so it knows where to find the correct asset.

resolve : { alias: { 'json-schema-parser': __dirname + '/node_modules/json-schema-ref-parser/dist/ref-parser.js' } }

and you use it as you would normally but use the alias key

var parser = require('json-schema-parser')

@JamesMessinger
Copy link
Member

Closing this issue, since it's a WebPack config issue. Thanks to @mari0juric for posting a solution, which will help others who are facing this problem. 👍

sramam added a commit to sramam/json-schema-ref-parser that referenced this issue Nov 29, 2016
Adding the "browser" field to package.json.
For details, see: https://github.com/defunctzombie/package-browser-field-spec

Useful when one is not using bower to install this package. Atleast webpack seems to pick this up without issue.
Webpack seems to support it - seems like an elegant solution for mixed usage libraries. 

Seems to be a better solution than APIDevTools#27 APIDevTools#27
@iamakulov
Copy link

FYI: the latest package on npm doesn’t have the browser field for some reason: https://unpkg.com/[email protected]/package.json. This breaks my webpack build.

Probably bumping the version and re-releasing the package could fix the problem? Or is the field removed during the publish routine (npm run release)?

@iamakulov
Copy link

Ah, yeah, it’s not published because the latest release was before #30 was merged.

Is there a chance that these changes will be published?

@JamesMessinger
Copy link
Member

I just released v3.2.0, which includes the browser field in the package.json file

@iamakulov
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants