google / schemarama

Schemarama is a project exploring standards-based validation for structured data, especially Schema.org.
Apache License 2.0
124 stars 22 forks source link

Remove hard dependency on fs #22

Closed elizusha closed 3 years ago

elizusha commented 3 years ago

When trying to use schemarama from npm for code that will be running in browser the following errors appear:

ERROR in /home/elizusha/schemarama/core/util.js
Module not found: Error: Can't resolve 'fs' in '/home/elizusha/schemarama/core'
 @ /home/elizusha/schemarama/core/util.js 17:11-24
 @ /home/elizusha/schemarama/core/index.js
 @ ./src/index.js

ERROR in /home/elizusha/schemarama/core/third_party/shex/shex.js
Module not found: Error: Can't resolve 'fs' in '/home/elizusha/schemarama/core/third_party/shex'
 @ /home/elizusha/schemarama/core/third_party/shex/shex.js 7664:17-30
 @ /home/elizusha/schemarama/core/shexValidator.js
 @ /home/elizusha/schemarama/core/index.js
 @ ./src/index.js

I think that the problem is that fs module is only available for node.js. In browsers you cannot have access to the file system anyway. This PR removes hard dependency on fs module: if it's available it will be used, if it's not available it will not throw an error unless you try to load a local file.

elizusha commented 3 years ago

Sorry, I realized it can be solved on my end by adding this to the webpack config:

  node: {
    fs: 'empty'
  }