dashevo / js-dpp

DEPRECATED The JavaScript implementation of the Dash Platform Protocol
MIT License
8 stars 8 forks source link

(? Webpack) unable to resolve schema files without .json file extension #172

Open cloudwheels opened 4 years ago

cloudwheels commented 4 years ago

Context I am working with webpack (4.43.0) to create a bundle for which the npm module @dashevo/dpp@0.12.1 is a dependency.

Webpack is unable to build successfully due to the errors below. On investigation, the require() statements for json schema files do not specify the file extension in the path. Adding the .json extension appears to resolve the issue

I will investigate whether I am able to fully resolve this issue and provide a PR if that is the case.

My assumption is that the library is able to build under other circumstances and this is a webpack issue. Webpack does not require a JSON file loader but there may be a configuration issue as to why files cannot be imported without the extension. There doesn't appear any special configuration related to .json imports in the webpack configuration for the library

Error output from Webpack:

ERROR in ./node_modules/@dashevo/dpp/lib/document/stateTransition/validation/structure/validateDocumentsBatchTransitionStructureFactory.js
Module not found: Error: Can't resolve '../../../../../schema/document/stateTransition/documentTransition/base' in '/home/nigel/Dev/dashmachine-crypto/node_modules/@dashevo/dpp/lib/document/stateTransition/validation/structure'
 @ ./node_modules/@dashevo/dpp/lib/document/stateTransition/validation/structure/validateDocumentsBatchTransitionStructureFactory.js 12:29-110
 @ ./node_modules/@dashevo/dpp/lib/stateTransition/StateTransitionFacade.js
 @ ./node_modules/@dashevo/dpp/lib/DashPlatformProtocol.js
 @ ./src/dashmachine-crypto.js
 @ multi ./src/dashmachine-crypto.js

ERROR in ./node_modules/@dashevo/dpp/lib/document/stateTransition/validation/structure/validateDocumentsBatchTransitionStructureFactory.js
Module not found: Error: Can't resolve '../../../../../schema/document/stateTransition/documentTransition/create' in '/home/nigel/Dev/dashmachine-crypto/node_modules/@dashevo/dpp/lib/document/stateTransition/validation/structure'
 @ ./node_modules/@dashevo/dpp/lib/document/stateTransition/validation/structure/validateDocumentsBatchTransitionStructureFactory.js 13:31-114
 @ ./node_modules/@dashevo/dpp/lib/stateTransition/StateTransitionFacade.js
 @ ./node_modules/@dashevo/dpp/lib/DashPlatformProtocol.js
 @ ./src/dashmachine-crypto.js
 @ multi ./src/dashmachine-crypto.js

ERROR in ./node_modules/@dashevo/dpp/lib/document/stateTransition/validation/structure/validateDocumentsBatchTransitionStructureFactory.js
Module not found: Error: Can't resolve '../../../../../schema/document/stateTransition/documentTransition/replace' in '/home/nigel/Dev/dashmachine-crypto/node_modules/@dashevo/dpp/lib/document/stateTransition/validation/structure'
 @ ./node_modules/@dashevo/dpp/lib/document/stateTransition/validation/structure/validateDocumentsBatchTransitionStructureFactory.js 14:32-116
 @ ./node_modules/@dashevo/dpp/lib/stateTransition/StateTransitionFacade.js
 @ ./node_modules/@dashevo/dpp/lib/DashPlatformProtocol.js
 @ ./src/dashmachine-crypto.js
 @ multi ./src/dashmachine-crypto.js

ERROR in ./node_modules/@dashevo/dpp/lib/identity/validation/validateIdentityFactory.js
Module not found: Error: Can't resolve '../../../schema/identity/identity' in '/home/nigel/Dev/dashmachine-crypto/node_modules/@dashevo/dpp/lib/identity/validation'
 @ ./node_modules/@dashevo/dpp/lib/identity/validation/validateIdentityFactory.js 1:23-67
 @ ./node_modules/@dashevo/dpp/lib/identity/IdentityFacade.js
 @ ./node_modules/@dashevo/dpp/lib/DashPlatformProtocol.js
 @ ./src/dashmachine-crypto.js
 @ multi ./src/dashmachine-crypto.js

ERROR in ./node_modules/@dashevo/dpp/lib/stateTransition/validation/validateStateTransitionStructureFactory.js
Module not found: Error: Can't resolve '../../../schema/stateTransition/stateTransitionBase' in '/home/nigel/Dev/dashmachine-crypto/node_modules/@dashevo/dpp/lib/stateTransition/validation'
 @ ./node_modules/@dashevo/dpp/lib/stateTransition/validation/validateStateTransitionStructureFactory.js 12:19-81
 @ ./node_modules/@dashevo/dpp/lib/stateTransition/StateTransitionFacade.js
 @ ./node_modules/@dashevo/dpp/lib/DashPlatformProtocol.js
 @ ./src/dashmachine-crypto.js
 @ multi ./src/dashmachine-crypto.js

ERROR in ./node_modules/@dashevo/dpp/lib/validation/JsonSchemaValidator.js
Module not found: Error: Can't resolve '../../schema/dataContract/dataContractMeta' in '/home/nigel/Dev/dashmachine-crypto/node_modules/@dashevo/dpp/lib/validation'
 @ ./node_modules/@dashevo/dpp/lib/validation/JsonSchemaValidator.js 1:31-84
 @ ./node_modules/@dashevo/dpp/lib/DashPlatformProtocol.js
 @ ./src/dashmachine-crypto.js
 @ multi ./src/dashmachine-crypto.js

ERROR in ./node_modules/@dashevo/dpp/lib/stateTransition/StateTransitionFacade.js
Module not found: Error: Can't resolve '../../schema/dataContract/stateTransition/dataContractCreate' in '/home/nigel/Dev/dashmachine-crypto/node_modules/@dashevo/dpp/lib/stateTransition'
 @ ./node_modules/@dashevo/dpp/lib/stateTransition/StateTransitionFacade.js 12:43-114
 @ ./node_modules/@dashevo/dpp/lib/DashPlatformProtocol.js
 @ ./src/dashmachine-crypto.js
 @ multi ./src/dashmachine-crypto.js

ERROR in ./node_modules/@dashevo/dpp/lib/dataContract/validateDataContractFactory.js
Module not found: Error: Can't resolve '../../schema/document/documentBase' in '/home/nigel/Dev/dashmachine-crypto/node_modules/@dashevo/dpp/lib/dataContract'
 @ ./node_modules/@dashevo/dpp/lib/dataContract/validateDataContractFactory.js 6:27-72
 @ ./node_modules/@dashevo/dpp/lib/dataContract/DataContractFacade.js
 @ ./node_modules/@dashevo/dpp/lib/DashPlatformProtocol.js
 @ ./src/dashmachine-crypto.js
 @ multi ./src/dashmachine-crypto.js

ERROR in ./node_modules/@dashevo/dpp/lib/document/validateDocumentFactory.js
Module not found: Error: Can't resolve '../../schema/document/documentBase' in '/home/nigel/Dev/dashmachine-crypto/node_modules/@dashevo/dpp/lib/document'
 @ ./node_modules/@dashevo/dpp/lib/document/validateDocumentFactory.js 2:27-72
 @ ./node_modules/@dashevo/dpp/lib/document/DocumentFacade.js
 @ ./node_modules/@dashevo/dpp/lib/DashPlatformProtocol.js
 @ ./src/dashmachine-crypto.js
 @ multi ./src/dashmachine-crypto.js

ERROR in ./node_modules/@dashevo/dpp/lib/stateTransition/StateTransitionFacade.js
Module not found: Error: Can't resolve '../../schema/document/stateTransition/documentsBatch' in '/home/nigel/Dev/dashmachine-crypto/node_modules/@dashevo/dpp/lib/stateTransition'
 @ ./node_modules/@dashevo/dpp/lib/stateTransition/StateTransitionFacade.js 13:39-102
 @ ./node_modules/@dashevo/dpp/lib/DashPlatformProtocol.js
 @ ./src/dashmachine-crypto.js
 @ multi ./src/dashmachine-crypto.js

ERROR in ./node_modules/@dashevo/dpp/lib/stateTransition/StateTransitionFacade.js
Module not found: Error: Can't resolve '../../schema/identity/stateTransition/identityCreate' in '/home/nigel/Dev/dashmachine-crypto/node_modules/@dashevo/dpp/lib/stateTransition'
 @ ./node_modules/@dashevo/dpp/lib/stateTransition/StateTransitionFacade.js 14:39-102
 @ ./node_modules/@dashevo/dpp/lib/DashPlatformProtocol.js
 @ ./src/dashmachine-crypto.js
 @ multi ./src/dashmachine-crypto.js
antouhou commented 4 years ago

@cloudwheels Hm that looks strange. We are building the lib with a webpack when we deploy it to npm, so there's already a minified version of this in the npm package, and it works. It's located under node_modules/@dashevo/dpp/dist/DashPlatformProtocol.min.js

I think we need to add "browser" field pointing to this file in package.json so Webpack won't bundle it twice

shumkov commented 4 years ago

"browser" field is evil! :). It breaks build for libraries that use DPP as a dependency.