liferay / liferay-js-toolkit

GNU Lesser General Public License v3.0
52 stars 41 forks source link

Use npm libraries inside a react app #629

Closed Lcpp0 closed 4 years ago

Lcpp0 commented 4 years ago

I'm trying to use crypto-js import * as CryptoJS from 'crypto-js' but got this error:

Error: The following problems where detected while resolving modules: · Missing dependency ':ERROR:Missing version constraints for actualizar-perfil$crypto in package.json of actualizar-perfil$crypto-js@4.0.0' of 'actualizar-perfil$crypto-js@4.0.0/core'

Dependency is listed in package.json file:

"dependencies": {
        "babel-plugin-transform-class-properties": "^6.24.1",
        "babel-plugin-transform-object-rest-spread": "^6.26.0",
        "crypto-js": "^4.0.0",
        "react": "16.8.6",
        "react-dom": "16.8.6"
    }, 

Inspecting liferay-npm-bundler-report.html I found this warn:

Post-phase plugin inject-peer-dependencies {} WARN Failed to resolve dependency actualizar-perfil$crypto with error: Error Cannot find module 'crypto/package.json' from '.\node_modules\crypto-js'

izaera commented 4 years ago

The missing package is crypto, not crypto-js. That's a node package that won't be available in Liferay, as it is a different platform.

You may need a shim/polyfill for crypto...