Uncaught Error: Cannot find module 'openpgp'

Lbrth_BoC

I'm learning javascript, and I tried to import some modules using npm in my js file. To import some module using require() it works fine, but I don't know why, for openpgp.js I got a

Uncaught Error: Cannot find module 'openpgp'.

Here my package.json :

{
  "name": "User",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
    "openpgp": "^2.5.1",
    "truffle-artifactor": "^2.1.2"
 },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": ""
}

Here the setup of my app : app config

  1. I run npm install openpgp inside my js file.

  2. In my js I import modules by typing var openpgp = require('openpgp');,

  3. Then I refreshed my browser and see my error : browser error

For information, when I using the node console, modules works fine!

I'm really new in javascript, so may be I do something wrong. If someone have an idea it's would be helpful !

Danibix

In order to require Node modules in browser script as in Node you need an external library. For example, you can use browserify lib.

Browserify let you bundle your scripts with needed dependencies into a single file that can be included in your web page.


Browserfiy website and docs should be enough clear. I report here main steps:

  1. Install browserify on your system:

    npm install -g browserify
    
  2. Bundle scripts with the require("openpgp") with the following command:

    browserify yourScriptName.js -o bundleFile.js
    

    (where -o parameter is for choosing the output file, if omitted browserify will print output on stdout)

  3. Now you can include the previous output in your with web page with the following tag:

    <script src="bundleFile.js"></script>
    

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Javascript

Error: Cannot find module html

From Dev

EXCEPTION: Uncaught (in promise): Error: Cannot find module 'app/home/home.module'

From Dev

Uncaught Error: Cannot Find Module When Using Dynamic Import for JavaScript

From Dev

Uncaught Error: Cannot find module "fs" when using webpack

From Dev

Error: Cannot find module 'commander'

From Dev

Ionic Uncaught Error: Cannot find module "." when importing a service provider

From Dev

How can I resolve Ionic Uncaught Error: Cannot find module "." when adding new page?

From Dev

Uncaught Error: Cannot find module 'stream'

From Dev

Ionic3 - Uncaught Error: Cannot find module '.'

From Dev

Ionic 4 / Angular Routing: ERROR Error: Uncaught (in promise): Error: Cannot find 'EventHomePageModule' in './home/home.module'

From Dev

React and Docker - Uncaught Error: Cannot find module 'react-player'

From Dev

Issue with jsPDF: Uncaught (in Promise) Error: Could not load dompurify: Error: cannot find module 'dompurify'

From Dev

webpacker Uncaught Error: Module build failed / Cannot find module 'babel-plugin-syntax-dynamic-import'

From Dev

Uncaught Error: Cannot find module 'redux'

From Dev

Error: Cannot find module 'mongodb'

From Dev

Uncaught Error: Cannot find module "./RandomWords"

From Dev

Error: Cannot find module './'

From Dev

Where is the error that is resulting in this Uncaught Error: Cannot find module "./users/UserSection.jsx" message?

From Dev

Meteor Error: Uncaught Error: Cannot find module 'component.jsx'

From Dev

Routing module stop working: Uncaught (in promise): Error: Cannot find 'xxxModule'

From Dev

Console error "Uncaught Error: Cannot find module "/axios" at webpackMissingModule" with react

From Dev

Dynamic import components error - Uncaught (in promise) Error: Cannot find module

From Dev

ERROR Error: Uncaught (in promise): Error: Cannot find module './user/user.module'

From Dev

Why I get "Uncaught Error: Cannot find module 'multi.js' " when module is installed globally?

From Dev

Uncaught Error: Cannot find module 'firebase' when trying to use serverTimestamp in firestore

From Dev

Uncaught Error: Cannot find module './imgShop/X React

From Dev

Uncaught Error: Cannot find module './recipes' in React Native

From Dev

Uncaught Error: Cannot find module 'firebase'

From Dev

Parcel 2 - Uncaught Error: Cannot find module 'axios'

Related Related

  1. 1

    Error: Cannot find module html

  2. 2

    EXCEPTION: Uncaught (in promise): Error: Cannot find module 'app/home/home.module'

  3. 3

    Uncaught Error: Cannot Find Module When Using Dynamic Import for JavaScript

  4. 4

    Uncaught Error: Cannot find module "fs" when using webpack

  5. 5

    Error: Cannot find module 'commander'

  6. 6

    Ionic Uncaught Error: Cannot find module "." when importing a service provider

  7. 7

    How can I resolve Ionic Uncaught Error: Cannot find module "." when adding new page?

  8. 8

    Uncaught Error: Cannot find module 'stream'

  9. 9

    Ionic3 - Uncaught Error: Cannot find module '.'

  10. 10

    Ionic 4 / Angular Routing: ERROR Error: Uncaught (in promise): Error: Cannot find 'EventHomePageModule' in './home/home.module'

  11. 11

    React and Docker - Uncaught Error: Cannot find module 'react-player'

  12. 12

    Issue with jsPDF: Uncaught (in Promise) Error: Could not load dompurify: Error: cannot find module 'dompurify'

  13. 13

    webpacker Uncaught Error: Module build failed / Cannot find module 'babel-plugin-syntax-dynamic-import'

  14. 14

    Uncaught Error: Cannot find module 'redux'

  15. 15

    Error: Cannot find module 'mongodb'

  16. 16

    Uncaught Error: Cannot find module "./RandomWords"

  17. 17

    Error: Cannot find module './'

  18. 18

    Where is the error that is resulting in this Uncaught Error: Cannot find module "./users/UserSection.jsx" message?

  19. 19

    Meteor Error: Uncaught Error: Cannot find module 'component.jsx'

  20. 20

    Routing module stop working: Uncaught (in promise): Error: Cannot find 'xxxModule'

  21. 21

    Console error "Uncaught Error: Cannot find module "/axios" at webpackMissingModule" with react

  22. 22

    Dynamic import components error - Uncaught (in promise) Error: Cannot find module

  23. 23

    ERROR Error: Uncaught (in promise): Error: Cannot find module './user/user.module'

  24. 24

    Why I get "Uncaught Error: Cannot find module 'multi.js' " when module is installed globally?

  25. 25

    Uncaught Error: Cannot find module 'firebase' when trying to use serverTimestamp in firestore

  26. 26

    Uncaught Error: Cannot find module './imgShop/X React

  27. 27

    Uncaught Error: Cannot find module './recipes' in React Native

  28. 28

    Uncaught Error: Cannot find module 'firebase'

  29. 29

    Parcel 2 - Uncaught Error: Cannot find module 'axios'

HotTag

Archive