Skip to content

Using npm package inside cordova project #386

Answered by breautek
KRC2000 asked this question in Q&A
Discussion options

You must be logged in to vote

Cordova runs in a webview, which is comparable to a browser.

Node, while runs in a JS engine like the browser, is a very different environment with different APIs (e.g. there is no require in the browser as that is a Node module concept)

It is possible to pull node packages and bundle them for the browser, but Cordova doesn't do this. In fact Cordova is unopinionated, you provide your built JS files and cordova will include them in the app binary. The only requirement is the JS should be able to run in a browser environment. Therefore to include node modules, you'll need to use a bundler tool such as Webpack, Browserify, or Rollup to name a few.

However even if you use those tools, the mo…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@KRC2000
Comment options

Answer selected by KRC2000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants