Ionic > Cannot find module 'ansi' - android

Building an Ionic project on a mac, throws the following error: Cannot find module 'ansi'
Command: ionic build android
Stacktrace
module.js:327
throw err;
^
Error: Cannot find module 'ansi'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/Users/bob/myapp/platforms/android/cordova/node_modules/cordova-common/src/CordovaLogger.js:20:12)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
Error: /Users/bob/myapp/platforms/android/cordova/build: Command failed with exit code 1
N.B. Simply installing the missing module doesn't work (i.e. npm install ansi), as it complains about other missing modules...

I'm not sure why the issue occurs (maybe someone can enlighten me), but removing and re-adding the Android platform fixes the issue.
i.e.
ionic platform remove android
ionic platform add android

Related

How do I fix React Native npm react-native init issue?

I write npm react-native init newApp but it returns a problem in this form.I downloaded the metro package (npm i metro) but it didn't fix the problem.Could this problem be due to missing any packages?
Error: Cannot find module './Bundler/util'
Require stack:
- C:\Users\kamra\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\metro\src\Assets.js
- C:\Users\kamra\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\metro\src\Server.js
- C:\Users\kamra\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\metro\src\shared\output\bundle.flow.js
- C:\Users\kamra\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\metro\src\shared\output\bundle.js
- C:\Users\kamra\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli-plugin-metro\build\commands\bundle\buildBundle.js
- C:\Users\kamra\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli-plugin-metro\build\commands\bundle\bundle.js
- C:\Users\kamra\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli-plugin-metro\build\commands\bundle\index.js
- C:\Users\kamra\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli-plugin-metro\build\commands\index.js
- C:\Users\kamra\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli-plugin-metro\build\index.js
- C:\Users\kamra\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\commands\index.js
- C:\Users\kamra\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\index.js
- C:\Users\kamra\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\bin.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
at Module._load (node:internal/modules/cjs/loader:885:27)
at Module.require (node:internal/modules/cjs/loader:1105:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (C:\Users\kamra\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\metro\src\Assets.js:14:32)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12)
at Module.require (node:internal/modules/cjs/loader:1105:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\kamra\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\metro\\src\\Assets.js',
'C:\\Users\\kamra\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\metro\\src\\Server.js',
'C:\\Users\\kamra\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\metro\\src\\shared\\output\\bundle.flow.js',
'C:\\Users\\kamra\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\metro\\src\\shared\\output\\bundle.js',
'C:\\Users\\kamra\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli-plugin-metro\\build\\commands\\bundle\\buildBundle.js',
'C:\\Users\\kamra\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli-plugin-metro\\build\\commands\\bundle\\bundle.js',
'C:\\Users\\kamra\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli-plugin-metro\\build\\commands\\bundle\\index.js',
'C:\\Users\\kamra\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli-plugin-metro\\build\\commands\\index.js',
'C:\\Users\\kamra\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli-plugin-metro\\build\\index.js',
'C:\\Users\\kamra\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\build\\commands\\index.js',
'C:\\Users\\kamra\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\build\\index.js',
'C:\\Users\\kamra\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\build\\bin.js'
]
}
Node.js v18.13.0

How to fix Invalid or unexpected token issue when running "ionic cordova build android" command?

I am trying to generate an APK of my ionic applications. ionic serve render without errors, but when i run ionic cordova build android it give me this error :
i've already try to uninstall then install cordova without results.
C:\Users\Nacim\AppData\Roaming\npm\node_modules\cordova\node_modules\currently-unhandled\core.js:1
(function (exports, require, module, __filename, __dirname) {
SyntaxError: Invalid or unexpected token
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\Nacim\AppData\Roaming\npm\node_modules\cordova\node_modules\currently-unhandled\index.js:2:12)
[ERROR] An error occurred while running subprocess cordova.
cordova build android --verbose exited with exit code 1.
Any idea of the root of the issue ?
Uninstaling then instaling ionic and cordova resolve the issue. It was caused by some missing dependancies in cordova and ionic package due to poor internet connexion.

Cordova build fails

When i run cordova run android cli it gives me this error. I am unable to find the solution on internet. cli.js is present in the src folder. I don't know what is causing the problem.
Thanks in advance
module.js:340
throw err;
^
Error: Cannot find module '../src/cli'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:289:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (C:\Users\App Metrik- Designer\AppData\Roaming\npm\cor
dova:40:11)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Function.Module.runMain (module.js:467:10)

react-native run-android command fails

On ubuntu 14.04 I try to launch hello world project.
I get the following output when print react-native run-android
/home/jonstark/AwesomeProject/node_modules/react-native/local-cli/cli.js:73
const setupEnvScript = /^win/.test(process.platform)
^^^^^
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:439:25)
at Module._extensions..js (module.js:474:10)
at Object.require.extensions.(anonymous function) [as .js] (/home/jonstark/AwesomeProject/node_modules/babel-register/lib/node.js:138:7)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (/home/jonstark/AwesomeProject/node_modules/react-native/cli.js:15:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
What do I do to get it working?
I tried to update nodejs with sudo npm install -g n
Then node -v shows
v0.10.25
Your node version is horribly outdated. See here for steps on how to update it on Ubuntu:
https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version

Getting Error in Cordova Installation in Mac Terminal

I've followed http://docs.phonegap.com/en/3.3.0/guide_cli_index.md.html#The%20Command-Line%20Interface.
When,I type in Mac Terminal
cordova create hello com.example.hello HelloWorld
The Error is-
path.js:360
throw new TypeError('Arguments to path.join must be strings');
^
ypeError: Arguments to path.join must be strings
at path.js:360:15
at Array.filter (native)
at Object.exports.join (path.js:358:36)
at Object.<anonymous> (/usr/local/lib/node_modules/cordova/src/util.js:25:31)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
Please if any one have any Idea about the cause of error and How it can be resolved. Please Share it.
Thanks in Advance.!!
Yes Finally Got the Solution. Steps to Follow-
Install latest version of Node HERE
Open vim .bash_profile in terminal
Type export PATH=${PATH}: <Android SDK Tools Path>
Type source .bash_profile in Terminal
and finally follow HERE

Categories

Resources