I'm using nativescript 6.1.1 with Angular 8.0 and my backend is Rails 5.x. I'm trying to use a npm plugin called angular-token which I have working in Angular but not in nativescript.
The error I get is;
Installing on device emulator-5554...
Successfully installed on device with identifier 'emulator-5554'.
Restarting application on device emulator-5554...
Successfully synced application org.nativescript.AssetManagementPrototype on device emulator-5554.
JS: HMR: Hot Module Replacement Enabled. Waiting for signal.
JS: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
JS: ERROR Error: Uncaught (in promise): ReferenceError: localStorage is not defined
JS: ReferenceError: localStorage is not defined
JS: at new AngularTokenService (file:///node_modules/angular-token/fesm5/angular-token.js:40:0)
JS: at _createClass (file:///node_modules/#angular/core/fesm5/core.js:18515:0)
JS: at _createProviderInstance (file:///node_modules/#angular/core/fesm5/core.js:18477:0)
JS: at resolveNgModuleDep (file:///node_modules/#angular/core/fesm5/core.js:18441:0)
JS: at NgModuleRef_.push.../node_modules/#angular/core/fesm5/core.js.NgModuleRef_.get (file:///node_modules/#angular/core/fesm5/core.js:19149:0)
JS: at resolveNgModuleDep (file:///node_modules/#angular/core/fesm5/core.js:18460:0)
JS: at NgModuleRef_.push.../node_modules/#angular/core/fesm5/core.js.NgModuleRef_.get (file:///data/data/org.nativescript.AssetManagem...
I've tried adding the #proplugins/nativescript-localstorage to my project, but that didn't help as the plugin angular-token needs to access the localstorage. I forked angular-token and tried adding #proplugins/nativescript-localstorage to it but get a build error here;
BUILD ERROR
projects/angular-token/src/lib/angular-token.service.ts(11,31): error TS7016: Could not find a declaration file for module '#proplugins/nativescript-localstorage'. '/home/map7/code/angular-token/node_modules/#proplugins/nativescript-localstorage/localstorage.js' implicitly has an 'any' type.
Try `npm install #types/proplugins__nativescript-localstorage` if it exists or add a new declaration (.d.ts) file containing `declare module '#proplugins/nativescript-localstorage';`
Error: projects/angular-token/src/lib/angular-token.service.ts(11,31): error TS7016: Could not find a declaration file for module '#proplugins/nativescript-localstorage'. '/home/map7/code/angular-token/node_modules/#proplugins/nativescript-localstorage/localstorage.js' implicitly has an 'any' type.
Try `npm install #types/proplugins__nativescript-localstorage` if it exists or add a new declaration (.d.ts) file containing `declare module '#proplugins/nativescript-localstorage';`
at Object.<anonymous> (/home/map7/code/angular-token/node_modules/ng-packagr/lib/ngc/compile-source-files.js:65:19)
at Generator.next (<anonymous>)
at fulfilled (/home/map7/code/angular-token/node_modules/ng-packagr/lib/ngc/compile-source-files.js:4:58)
projects/angular-token/src/lib/angular-token.service.ts(11,31): error TS7016: Could not find a declaration file for module '#proplugins/nativescript-localstorage'. '/home/map7/code/angular-token/node_modules/#proplugins/nativescript-localstorage/localstorage.js' implicitly has an 'any' type.
Try `npm install #types/proplugins__nativescript-localstorage` if it exists or add a new declaration (.d.ts) file containing `declare module '#proplugins/nativescript-localstorage';`
Error: projects/angular-token/src/lib/angular-token.service.ts(11,31): error TS7016: Could not find a declaration file for module '#proplugins/nativescript-localstorage'. '/home/map7/code/angular-token/node_modules/#proplugins/nativescript-localstorage/localstorage.js' implicitly has an 'any' type.
Try `npm install #types/proplugins__nativescript-localstorage` if it exists or add a new declaration (.d.ts) file containing `declare module '#proplugins/nativescript-localstorage';`
at Object.<anonymous> (/home/map7/code/angular-token/node_modules/ng-packagr/lib/ngc/compile-source-files.js:65:19)
at Generator.next (<anonymous>)
at fulfilled (/home/map7/code/angular-token/node_modules/ng-packagr/lib/ngc/compile-source-files.js:4:58)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! angular-token-app#0.0.0 build:lib: `ng build --prod angular-token && cp README.md dist/angular-token`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the angular-token-app#0.0.0 build:lib script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/map7/.npm/_logs/2019-09-17T23_53_33_058Z-debug.log
How do I get the angular-token working in NativeScript?
Related
The SAFE Stack Documentation says to install npm (amongst other things) as a pre-requisite to build SAFE apps. But the link refers to https://www.npmjs.com where you have to search for packages. But which ones? What to install? There are thousands of packages there.
UPDATE:
I have just noticed that the npm documentation says that npm comes bundled with node, & most third-party distributions, by default. So why does the SAFE Stack documentation show the link to npm? Is there any sense in it?
I have tried to install the npm package via NuGet. But whatever I do, running the SAFE standard template in VS ends with a NullReferenceException:
File helpers.fs
let runOrDefault args =
try
match args with
| [| target |] -> Target.runOrDefault target
| _ -> Target.runOrDefault "Run" //NullReferenceException
0
with e ->
printfn "%A" e
1
Entering dotnet run through a command prompt opens a console window containing these messages:
Starting target 'InstallClient'
.> "C:\Program Files\nodejs\npm.CMD" install (In: false, Out: false, Err: false)
npm ERR! code EBADENGINE
npm ERR! engine Unsupported engine
npm ERR! engine Not compatible with your version of node/npm: undefined
npm ERR! notsup Not compatible with your version of node/npm: undefined
npm ERR! notsup Required: {"node":"~16","npm":"~8"}
npm ERR! notsup Actual: {"npm":"8.19.2","node":"v19.0.0"}
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\User\AppData\Local\npm-cache\_logs\2022-11-04T11_38_04_408Z-debug-0.log
Finished (Failed) 'InstallClient' in 00:00:02.0540071
UPDATE:
In line with Tomáš Petříček's recommendation, I installed this version of node.js: Latest LTS Version: 18.12.0 (includes npm 8.19.2)
But again, NullReferenceException in VS, and the following error messages appear when using the command prompt:
Starting target 'InstallClient'
.> "C:\Program Files\nodejs\npm.CMD" install (In: false, Out: false, Err: false)
npm ERR! code EBADENGINE
npm ERR! engine Unsupported engine
npm ERR! engine Not compatible with your version of node/npm: undefined
npm ERR! notsup Not compatible with your version of node/npm: undefined
npm ERR! notsup Required: {"node":"~16","npm":"~8"}
npm ERR! notsup Actual: {"npm":"8.19.2","node":"v18.12.0"}
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\User\AppData\Local\npm-cache\_logs\2022-11-04T13_19_03_959Z-debug-0.log
Finished (Failed) 'InstallClient' in 00:00:01.9942657
---------------------------------------------------------------------
Build Time Report
---------------------------------------------------------------------
Target Duration
------ --------
Clean 00:00:00.5118885
InstallClient 00:00:01.9937254 (Process exit code '1' <> 0. Command Line: C:\Program Files\nodejs\npm.CMD install)
Run 00:00:00 (skipped)
Total: 00:00:02.6111670
Status: Failure
---------------------------------------------------------------------
Fake.Core.BuildFailedException: Target 'InstallClient' failed.
I think all you need to install is Node.js from the official download page There are two versions:
LTS (stable) - version 18 and
Current (development) - version 19
I previously installed "Current" and then run into various troubles (though different ones than you are reporting). You also seem to have 19 according to the log. I gave up with Current and reverted my setup to the LTS version. So perhaps uninstalling the Node version you have right now and installing Node LTS may help.
These adaptations made it possible to run the SAFE standard template on my PC in line with the Quick Start guidelines:
Pre-requisites:
The .NET 6 SDK //OK
node.js (>= 8.0) //OK
npm //do not use this link
Azure CLI (optional - required for Azure deployments) //OK
Continue with guidlines 1 to 6 in the "Create your first SAFE app" section. Use cmd for the dotnet run command.
Look at the node and npm versions in this error message example:
npm ERR! notsup Actual: {"npm":"8.19.2","node":"v18.12.0"}
You may have different versions of npm and node, of course.
In line with this article by Adam Johnson, do this:
Open package.json in the root folder of the template and change the versions of npm and node accordingly, like this:
"private": true,
"engines": {
"node": "18.x",
"npm": "8.x"
}
To suppress warnings, you may add *.npmrc file containing the text string engine-strict=true next to the package.json file.
This answer, however, does not solve the problem why there is a link to npm in the pre-requisites section.
The solution in this answer looks somewhat complicated so if you have got a better idea, it will be fine if you publish it.
UPDATE 08-Nov-2022
Instructions telling you how to run/debug a SAFE Stack app in Visual Studio are here. Then no more problems with NullReferenceExceptions.
My Electron application compiles and packages under MacOS without any problems but when it comes to Windows, I can't seem to make it work.
Here's the debug output:
Error: node-gyp failed to rebuild '[appfolder]\release\app\node_modules\cpu-features'.
For more information, rerun with the DEBUG environment variable set to "electron-rebuild".
Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
at NodeGyp.rebuildModule ([appfolder]\node_modules\electron-rebuild\lib\src\module-type\node-gyp.js:117:19)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async ModuleRebuilder.rebuildNodeGypModule ([appfolder]\node_modules\electron-rebuild\lib\src\module-rebuilder.js:94:9)
at async ModuleRebuilder.rebuild ([appfolder]\node_modules\electron-rebuild\lib\src\module-rebuilder.js:124:14)
at async Rebuilder.rebuildModuleAt ([appfolder]\node_modules\electron-rebuild\lib\src\rebuild.js:145:13)
at async Promise.all (index 7)
at async Rebuilder.rebuild ([appfolder]\node_modules\electron-rebuild\lib\src\rebuild.js:104:13)
at async [appfolder]\node_modules\electron-rebuild\lib\src\cli.js:154:9
Error: Command failed: ..\..\node_modules\.bin\electron-rebuild --parallel --force --types prod,dev,optional --module-dir .
at checkExecSyncError (child_process.js:790:11)
at execSync (child_process.js:863:15)
at Object.<anonymous> ([appfolder]\.erb\scripts\electron-rebuild.js:17:11)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Module.m._compile ([appfolder]\node_modules\ts-node\src\index.ts:1455:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Object.require.extensions.<computed> [as .js] ([appfolder]\node_modules\ts-node\src\index.ts:1458:12)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12) {
status: 4294967295,
signal: null,
output: [ null, null, null ],
pid: 2700,
stdout: null,
stderr: null
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! elapp#4.5.0 electron-rebuild: `node -r ts-node/register ../../.erb/scripts/electron-rebuild.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the elapp#4.5.0 electron-rebuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\elodie\AppData\Roaming\npm-cache\_logs\2022-04-17T20_38_46_086Z-debug.log
error Command failed with exit code 1.
failedTask=installAppDeps stackTrace=Error: C:\Program Files\nodejs\node.exe exited with code ERR_ELECTRON_BUILDER_CANNOT_EXECUTE
Output:
yarn install v1.22.18
[1/4] Resolving packages...
success Already up-to-date.
$ npm run electron-rebuild && npm run link-modules
Tried this with Node v14, 16 and 17 to no avail.
EDIT: Missed the actual error while posting. Here's the error from C++ compilation step:
> elapp#4.5.0 electron-rebuild [appfolder]\release\app
> node -r ts-node/register ../../.erb/scripts/electron-rebuild.js
Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
conpty.cc
conpty.cc
[appfolder]\release\app\node_modules\node-pty\src\win\conpty.cc : fatal error C1083: Cannot open compiler generated file: '[folder]\obj\conpty\src\win\conpty.obj': Permission denied [[appfolder]\release\app\node_modules\node-pty\build\conpty.vcxproj]
path_util.cc
conpty_console_list.cc
win_delay_load_hook.cc
win_delay_load_hook.cc
Creating library [folder]\conpty_console_list.lib and object [folder]\conpty_console_list.exp
Creating library [folder]\conpty.lib and object [folder]\conpty.exp
conpty_console_list.vcxproj -> [folder]\\conpty_console_list.node
conpty.vcxproj -> [folder]\\conpty.node
Agent.cc
conpty_console_list.vcxproj -> [folder]\\conpty_console_list.node
Agent.cc
[appfolder]\release\app\node_modules\node-pty\deps\winpty\src\agent\Agent.cc : fatal error C1083: Cannot open compiler generated file: '[appfolder]\release\app\node_modules\node-pty\build\deps\winpty\src\Release\obj\winpty-agent\deps\winpty\src\agent\Agent.obj': Permission denied [[appfolder]\release\app\node_modules\node-pty\build\deps\winpty\src\winpty-agent.vcxproj]
EDIT 2: Running the same command as an administrator lead to another error:
yarn install v1.22.18
[1/4] Resolving packages...
success Already up-to-date.
$ npm run electron-rebuild && npm run link-modules
> elapp#4.5.0 electron-rebuild C:\Users\elodie\Projects\elapp\release\app
> node -r ts-node/register ../../.erb/scripts/electron-rebuild.js
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Error output:
- Searching dependency tree
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
gyp: Call to 'cmd /c "cd shared && UpdateGenVersion.bat 2c681018ca7311741a0022e3a170bf60174590b2"' returned exit status 0 while in deps\winpty\src\winpty.gyp. while loading dependencies of binding.gyp while trying to load binding.gyp
× Rebuild Failed
An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild 'C:\Users\elodie\Projects\elapp\release\app\node_modules\node-pty'.
For more information, rerun with the DEBUG environment variable set to "electron-rebuild".
Error: `gyp` failed with exit code: 1
When I run "ionic cordova platform add ios", that got the following error. How to fix it?
Exception: Using cordova-fetch for cordova-ios#0.0.1
Error: Failed to fetch platform cordova-ios#0.0.1
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
Error: npm: Command failed with exit code 1 Error output:
npm ERR! code ETARGET
npm ERR! notarget No matching version found for cordova-ios#0.0.1
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/thanhnguyen/.npm/_logs/2017-08-25T10_34_19_961Z-debug.log
The following command should resolve the issue:
cordova platform add ios#latest
Inside my package.json there was a ios:0.0.1 which I removed and got resolved.
I'm installing laravel elixir on my latest homestead machine , working on laravel 5.3, i followed the exact documentation to install laravel elixir, but it didn't worked , it's throwing error regarding sass file. here is snapshot
How do i solve this issue.
test version is ->
```
[19:33:15] Using gulpfile ~/sites/dev.friendsforever/server/gulpfile.js
[19:33:15] Starting 'all'...
[19:33:15] Starting 'sass'...
[19:33:16] 'sass' errored after 169 ms
[19:33:16] Error: ENOENT: no such file or directory, scandir '/home/vagrant/sites/dev.friendsforever/server/node_modules/node-sass/vendor'
at Error (native)
at Object.fs.readdirSync (fs.js:856:18)
at Object.getInstalledBinaries (/home/vagrant/sites/dev.friendsforever/server/node_modules/node-sass/lib/extensions.js:119:13)
at foundBinariesList (/home/vagrant/sites/dev.friendsforever/server/node_modules/node-sass/lib/errors.js:20:15)
at foundBinaries (/home/vagrant/sites/dev.friendsforever/server/node_modules/node-sass/lib/errors.js:15:5)
at Object.module.exports.missingBinary (/home/vagrant/sites/dev.friendsforever/server/node_modules/node-sass/lib/errors.js:45:5)
at Object.<anonymous> (/home/vagrant/sites/dev.friendsforever/server/node_modules/node-sass/lib/index.js:15:28)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
[19:33:16] 'all' errored after 179 ms
[19:33:16] Error in plugin 'run-sequence(sass)'
Message:
ENOENT: no such file or directory, scandir '/home/vagrant/sites/dev.friendsforever/server/node_modules/node-sass/vendor'
Details:
errno: -2
code: ENOENT
syscall: scandir
path: /home/vagrant/sites/dev.friendsforever/server/node_modules/node-sass/vendor
Stack:
Error: ENOENT: no such file or directory, scandir '/home/vagrant/sites/dev.friendsforever/server/node_modules/node-sass/vendor'
at Error (native)
at Object.fs.readdirSync (fs.js:856:18)
at Object.getInstalledBinaries (/home/vagrant/sites/dev.friendsforever/server/node_modules/node-sass/lib/extensions.js:119:13)
at foundBinariesList (/home/vagrant/sites/dev.friendsforever/server/node_modules/node-sass/lib/errors.js:20:15)
at foundBinaries (/home/vagrant/sites/dev.friendsforever/server/node_modules/node-sass/lib/errors.js:15:5)
at Object.module.exports.missingBinary (/home/vagrant/sites/dev.friendsforever/server/node_modules/node-sass/lib/errors.js:45:5)
at Object.<anonymous> (/home/vagrant/sites/dev.friendsforever/server/node_modules/node-sass/lib/index.js:15:28)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
```
image version is ->
the problem is the incompatibility between OS and node js, so the solution is just run the command npm rebuild node-sass.
Just run npm rebuild node-sass from within your Host computer. If you have node installed on your computer, it will rebuild node-sass, detect whatever environment your Host computer is, and do something specific to that node-sass build.
Then run gulp command, hope it will work.
If you haven't figured it out by now, you can run
npm install node-sass --no-bin-links
from within the virtual machine and then gulp should work.
If you are getting "Error: ENOENT: no such file or directory..." error run this command. It worked for me.
npm rebuild node-sass
Reference: https://laracasts.com/discuss/channels/elixir/laravel-53-gulp-error-cannot-find-module-laravel-elixir-vue-2
I am trying to install "Twitter-Node" (npm install twitter-node). Version .3.2-pre of Node JS.
When I try and install I receive the follow error. Any thoughts on what I may be doing wrong? Seems like a pretty straight forward install to me. I was able successfully install socket-io too...
m ERR! Error: twitter-node#0.0.2 preinstall: `./build.sh`
npm ERR! `sh` failed with 1
npm ERR! at ChildProcess.<anonymous> (/usr/local/lib/node/.npm/npm/0.2.12- 1/package/lib/utils/exec.js:25:18)
npm ERR! at ChildProcess.emit (events.js:34:17)
npm ERR! at ChildProcess.onexit (child_process.js:164:12)
npm ERR!
npm ERR! Failed at the twitter-node#0.0.2 preinstall script.
npm ERR! This is most likely a problem with the twitter-node package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ./build.sh
Simple solution
Just grab it from here:
https://github.com/patmcnally/twitter-node
The module on npm is old (last update August 31th) and broken by design, it compiles its own base64 encoder instead of using Node's built in functionality.
To install:
Download the archive and extract it
cd into the folder and run npm install .
Have a nice day :)
Old answer
The install runs gcc to compile a base64 module that depends on nodes Buffer class (the C++ implementation), since there were quite some changes to that in 3.x, it explodes!
Waf: Entering directory `/home/ivo/.local/lib/node/.npm/twitter-node/0.0.2/package/vendor/node-base64/build'
[1/2] cxx: base64.cc -> build/default/base64_1.o
../base64.cc: In function ‘v8::Handle<v8::Value> base64_encode_binding(const v8::Arguments&)’:
../base64.cc:178: error: ‘class node::Buffer’ has no member named ‘data’
../base64.cc:178: error: ‘class node::Buffer’ has no member named ‘length’
../base64.cc: In function ‘v8::Handle<v8::Value> base64_decode_binding(const v8::Arguments&)’:
../base64.cc:199: error: ‘class node::Buffer’ has no member named ‘data’
../base64.cc:199: error: ‘class node::Buffer’ has no member named ‘length’
Waf: Leaving directory `/home/ivo/.local/lib/node/.npm/twitter-node/0.0.2/package/vendor/node-base64/build'
Build failed: -> task failed (err #1):
{task: cxx base64.cc -> base64_1.o}
This commit removed the two members and replaced them with static inlined methods.
In .npm/twitter-node/0.0.2/package/vendor/node-base64/base64.cc you need to replace the lines 177/178 and 198/199 which look like this:
Buffer *buffer = ObjectWrap::Unwrap<Buffer>(args[0]->ToObject());
char *str = base64_encode((unsigned char*)buffer->data(), buffer->length(),&len);
With this:
Local<Object> buffer = args[0]->ToObject();
char *str = base64_encode((unsigned char*)Buffer::Data(buffer), Buffer::Length(buffer),&len);
Then run npm rebuild twitter-node and you're done! Don't use install, as it will re-download and overwrite the changes.
PS: I had to use require('twitter-node#0.0.2') to get it to import, since npm didn't create the symlink in .local/lib/node but you can easily fix that on your own.
Update
I did take a look at the module, this is hilarious, they compile a 80kb lib which is prone to failure with changed to Node.js just to use a base64 encode ONE TIME.
// Returns a Basic Auth header fit for HTTP.
var basicAuth = function basicAuth(user, pass) {
return "Basic " + b64.encode(user + ":" + pass);
};
This does the exact same thing and doesn't explode on every other change to Node.js:
new Buffer(user + ':' + pass).toString('base64')