Search code examples
javascriptnode.jsfacebookjspm

jspm install npm:fb cannot find crypto


I use jspm to intall npm:fb, and use in my js, but I get

GET /jspm_packages/npm/[email protected] 404

my step:

jspm init

jspm install npm:fb

Should I add something to fix it?

My index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>try fb</title>
</head>
<body>
  <script src="jspm_packages/system.js"></script>
  <script src="config.js"></script>
  <script>
    System.import('lib/main.js')
  </script>
</body>
</html>

My lib/main.js

import fb from 'fb'

export default {}

Solution

  • As jspm says during the installation of fb:

    warn Main entry point not found for npm:[email protected].
         Adjust this property in the package.json or with an override, setting "main": false if this is the intention.
    

    So you can add the following override to your package.json:

    "overrides": {
      "npm:[email protected]": {
         "main": "md5.js"
       }
    }
    

    This chooses one of two files of the crypto module as main. This fixes the original problem. But you will get another one:

    Node tls module not supported in browsers.

    So I believe you need to find a browser-friendly version of fb.