Nativescript: Not being able to use node_module because it uses process.env inside

Created on 13 Nov 2016  路  3Comments  路  Source: NativeScript/NativeScript

Which platform(s) does your issue occur on?

Android

Please provide the following version numbers that your issue occurs with:

  • CLI: next
  • Cross-platform modules: next
  • Runtime(s): next

Please tell us how to recreate the issue in as much detail as possible.

The process global, available in node, isn't shimmed in NS, and it fails in some node_modules. there's no way to shim it either (either by using global.process, it doesn't injects to the require'd module)

package.json

{
   "dependencies": {
       "@google/maps": "^0.3.0",
   }
}
import { createClient } from '@google/maps'

const client = createClient({
   key: 'somekey'
})

client.geocode({ address: 'Washington, DC' }, () => {
})

crashes with:

W/System.err( 6682): Calling js method onCreateView failed
W/System.err( 6682): ReferenceError: process is not defined
W/System.err( 6682): File: "/data/data/org.nativescript.cadastramento/files/app/tns_modules/@google/maps/lib/internal/make-api-call.js, line: 25, column: 37
W/System.err( 6682): StackTrace:
W/System.err( 6682):    Frame: function:'exports.inject', file:'/data/data/org.nativescript.cadastramento/files/app/tns_modules/@google/maps/lib/internal/make-api-call.js', line: 25, column: 38
W/System.err( 6682):    Frame: function:'exports.createClient', file:'/data/data/org.nativescript.cadastramento/files/app/tns_modules/@google/maps/lib/index.js', line: 47, column: 57

tried to shim it in app.ts

import * as app from 'application'
import * as process from 'process/browser'

global.process = process

app.start({ moduleName: 'views/main' });

seems the globals doesn't get injected in require'd files

android question

Most helpful comment

@enchev browserify and others shim node specific code for the browser, so at least they don't break when trying to bundle. consider learning from them, will make NS more compatible with modules that have process.env in them

All 3 comments

Hey @pocesar,

process is node specific and cannot be used in NativeScript app.

@enchev browserify and others shim node specific code for the browser, so at least they don't break when trying to bundle. consider learning from them, will make NS more compatible with modules that have process.env in them

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings