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 Dev

Uncaught Error: Cannot find module "./RandomWords"

From Dev

Uncaught Error: Cannot find module 'stream'

From Dev

Uncaught Error: Cannot find module 'redux'

From Dev

Uncaught Error: Cannot find module 'firebase'

From Dev

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

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

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

From Dev

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

From Dev

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

From Dev

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

From Dev

Ionic3 - Uncaught Error: Cannot find 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

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

From Dev

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

From Dev

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

From Dev

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

From Dev

Error: Cannot find module './'

From Dev

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

From Dev

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

From Dev

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

From Dev

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

From Dev

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

From Dev

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

From Dev

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

From Dev

Error: Cannot find module 'commander'

From Dev

Error: Cannot find module 'mongodb'

From Javascript

Error: Cannot find module html

Related Related

  1. 1

    Uncaught Error: Cannot find module "./RandomWords"

  2. 2

    Uncaught Error: Cannot find module 'stream'

  3. 3

    Uncaught Error: Cannot find module 'redux'

  4. 4

    Uncaught Error: Cannot find module 'firebase'

  5. 5

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

  6. 6

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

  7. 7

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

  8. 8

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

  9. 9

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

  10. 10

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

  11. 11

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

  12. 12

    Ionic3 - Uncaught Error: Cannot find module '.'

  13. 13

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

  14. 14

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

  15. 15

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

  16. 16

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

  17. 17

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

  18. 18

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

  19. 19

    Error: Cannot find module './'

  20. 20

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

  21. 21

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

  22. 22

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

  23. 23

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

  24. 24

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

  25. 25

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

  26. 26

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

  27. 27

    Error: Cannot find module 'commander'

  28. 28

    Error: Cannot find module 'mongodb'

  29. 29

    Error: Cannot find module html

HotTag

Archive