Package Node-Red using zeit/pkg - node.js

I am having some issues using zeit/pkg on my node-red project. Here are the steps to replicate the issue:
git clone https://github.com/node-red/node-red.git
cd node-red
npm install
npm run build
After build command I added the following to my package.json file:
"pkg": {
"assets": [
"./red/**/*"
],
"scripts": [
"./red/**/*.js"
]
}
Run the command pkg .
After running pkg . I get the following errors:
C:\xampp\htdocs\node-red>pkg .
> pkg#4.3.4
> Targets not specified. Assuming:
node8-linux-x64, node8-macos-x64, node8-win-x64
> Warning Cannot resolve 'path.join(__dirname, '..', '..', 'package.json')'
C:\xampp\htdocs\node-red\red\runtime\index.js
Dynamic require may fail at run time, because the requested file
is unknown at compilation time and not included into executable.
Use a string literal as an argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option.
> Warning Cannot resolve ''./' + aSettings.storageModule'
C:\xampp\htdocs\node-red\red\runtime\storage\index.js
Dynamic require may fail at run time, because the requested file
is unknown at compilation time and not included into executable.
Use a string literal as an argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option.
> Warning Cannot resolve 'relPath'
C:\xampp\htdocs\node-red\red\runtime\nodes\registry\loader.js
Dynamic require may fail at run time, because the requested file
is unknown at compilation time and not included into executable.
Use a string literal as an argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option.
Running the exe after the pkg command gives me this error:
Node-RED has not been built. See README.md for details
Any help would be greatly appreciated. It seems like a simple path issue but I can't seem to get it working.

Related

VS Code error `failed to run build scripts` when using Rust-Analyzer only on one specific project

My company just switched on a new repo the Rust project I'm working on, to merge it with a Tauri project, and VS Code now gave me this error:
Failed to run build scripts
I can compile, run my project or use cargo check to see the warnings/error but Rust Analyzer is not working and it's very annoying for me to run cargo check every time i need to check my code.
This error occurs only on this repo, which contains a Rust workspace separate in two folders: one Tauri/Rust project and one basic Rust project.
Cargo.toml at the root:
[workspace]
members = [
"builder",
"studio/src-tauri"
]
Error details:
[ERROR rust_analyzer::lsp_utils] failed to run build scripts:
The following warnings were emitted during compilation:
error: failed to run custom build command for `cairo-sys-rs v0.15.1`
Caused by:
process didn't exit successfully: `/home/korocouille/Sogilis/IReflex/reflex2/target/debug/build/cairo-sys-rs-decf14405d906ced/build-script-build` (exit status: 1)
--- stdout
cargo:rerun-if-env-changed=CAIRO_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
cargo:warning=`"pkg-config" "--libs" "--cflags" "cairo" "cairo >= 1.14"` did not exit successfully: exit status: 1
error: could not find system library 'cairo' required by the 'cairo-sys-rs' crate
--- stderr
Package cairo was not found in the pkg-config search path.
Perhaps you should add the directory containing `cairo.pc'
to the PKG_CONFIG_PATH environment variable
No package 'cairo' found
Package cairo was not found in the pkg-config search path.
Perhaps you should add the directory containing `cairo.pc'
to the PKG_CONFIG_PATH environment variable
No package 'cairo' found
I tried to uninstall and re-install Rust-Analyzer, switch to pre-release or older version, delete my target folder, run a cargo clean cmd but nothing changed, and I can't find any solution.

How to compile Node.js with figlet module from pkg?

After compiling via pkg and running the .exe, I got the error:
(node:17672) UnhandledPromiseRejectionWarning: Error: File 'C:\**\mytestapp\node_modules\figlet\fonts\Ghost.flf' was not included into executable at compilation stage. Please recompile adding it as asset or script.
my index.js and package.json: https://pastebin.com/vL4nZcZW
I tried to add the entire figlet module to the asset, reinstall it and pkg, but this did not work. I tried to compile with only one require. What am I doing wrong?

Compiling fluoride bluetooth stack for embedded linux

Has anyone been able to compile fluoride bluetooth stack separately for an embedded linux device?
There is a guide at https://android.googlesource.com/platform/system/bt/+/181144a50114c824cfe3cdfd695c11a074673a5e/README.md, but following these instructions gn gen fails without getting the common-mk folder and modding some build files so there are no missing variables, folders etc.
I have been able to generate Ninja files, but when building, there are missing gtest and modp_b64 headers. After getting them from Google's source search, Ninja seems to be able to run a bit without errors, but ultimately fails with:
In file included from ../../third_party/libchrome/base/message_loop/message_loop.h:18:
../../third_party/libchrome/base/message_loop/message_loop_current.h:209:3: error: static_assert failed due to requirement 'std::is_same<MessagePumpForUI, MessagePumpLibevent>::value' "MessageLoopCurrentForUI::WatchFileDescriptor is not supported when MessagePumpForUI is not a MessagePumpLibevent."
static_assert(std::is_same<MessagePumpForUI, MessagePumpLibevent>::value,
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../third_party/libchrome/base/message_loop/message_loop_current.h:214:28: error: no type named 'Mode' in 'base::MessagePumpGlib'; did you mean 'MessagePumpLibevent::Mode'?
MessagePumpForUI::Mode mode,
^~~~~~~~~~~~~~~~~~~~~~
MessagePumpLibevent::Mode
../../third_party/libchrome/base/message_loop/watchable_io_message_pump_posix.h:55:8: note: 'MessagePumpLibevent::Mode' declared here
enum Mode {
^
In file included from ../../third_party/libchrome/base/run_loop.cc:10:
In file included from ../../third_party/libchrome/base/message_loop/message_loop.h:18:
../../third_party/libchrome/base/message_loop/message_loop_current.h:215:28: error: no type named 'FdWatchController' in 'base::MessagePumpGlib'; did you mean 'MessagePumpLibevent::FdWatchController'?
MessagePumpForUI::FdWatchController* controller,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MessagePumpLibevent::FdWatchController
../../third_party/libchrome/base/message_loop/message_pump_libevent.h:28:9: note: 'MessagePumpLibevent::FdWatchController' declared here
class FdWatchController : public FdWatchControllerInterface {
^
In file included from ../../third_party/libchrome/base/run_loop.cc:10:
In file included from ../../third_party/libchrome/base/message_loop/message_loop.h:18:
../../third_party/libchrome/base/message_loop/message_loop_current.h:216:28: error: no type named 'FdWatcher' in 'base::MessagePumpGlib'; did you mean 'MessagePumpLibevent::FdWatcher'?
MessagePumpForUI::FdWatcher* delegate);
^~~~~~~~~~~~~~~~~~~~~~~~~~~
MessagePumpLibevent::FdWatcher
../../third_party/libchrome/base/message_loop/watchable_io_message_pump_posix.h:17:9: note: 'MessagePumpLibevent::FdWatcher' declared here
class FdWatcher {
^
4 errors generated.
All the errors and missing files are coming from third_party/libchrome
Any help would be much appreciated.
I followed instructions at https://cs.android.com/android/platform/superproject/+/master:system/bt/README.md
In addition to instructions there, I had to resolve issues in the build script manually. I was able to compile the bluetooth stack successfully in Ubuntu 21.04
Replace //bt with /home/udara/fluoride/bt in build files.
Used sed command. Change to your fluoride directory as appropriate.
for file in $(grep -r -l "//bt"); do sed -i 's/\/\/bt/\/home\/udara\/fluoride\/bt/g' $file; done
Copied common-mk symlink generated by bootstrap.py to the fluoride directory.
And replaced //common-mk with /home/udara/fluoride/common-mk.
for file in $(grep -r -l "//common-mk"); do sed -i 's/\/\/common-mk/\/home\/udara\/fluoride\/common-mk/g' $file; done
Installed few missing dependencies
sudo apt install llvm
sudo apt install libc++abi-dev
Copied /home/udara/fluoride/bt/output/out/Default/gen/ABS_PATH/home/udara/fluoride/bt/gd/dumpsys/bundler/bundler_generated.h to /home/udara/fluoride/bt/gd/dumpsys/
cp /home/udara/fluoride/bt/output/out/Default/gen/ABS_PATH/home/udara/fluoride/bt/gd/dumpsys/bundler/bundler_generated.h /home/udara/fluoride/bt/gd/dumpsys/
Created directory named output in the bt directory.
Set environment variables
# this is set by bootstrap.py
export STAGING_DIR=/home/udara/fluoride/staging
# you have to manually set this
export OUTPUT_DIR=/home/udara/fluoride/bt/output
Then compile the bluetooth stack with
./build.py --output ${OUTPUT_DIR} --platform-dir ${STAGING_DIR} --clang
Add the following lines to /etc/dbus-1/system.d/bluetooth.conf
<policy>
...
<allow own="org.chromium.bluetooth"/>
<allow own="org.chromium.bluetooth.Manager"/>
</policy>
Finally run fluoride with
cd /home/udara/fluoride/bt/output/debug
sudo ./btadapterd --hci=0 INIT_gd_hci=true
The reason the common-mk issues are coming up because between the instructions being written, and now, libchrome has added a BUILD.gn file - so it is being used, instead of the substitute one in build/secondary/third-party/libchrome as intended. To fix this part of the build, just delete third-party/libchrome/BUILD.gn - should prevent the need for a lot of build fiddling.
The second part is because of the configuration of libchrome. Once you remove the file mentioned, then you need to modify build/secondary/third-party/libchrome/BUILD.gn to add the following not just to the source_set (as is done in upstream) but also to libchrome_config for downstream users:
defines = [
"__ANDROID_HOST__=1",
]
This will affect the build config so it doesn't try to use glib.
My best work on getting this to build is here, though I haven't gotten it to work entirely. https://github.com/rpavlik/fluoride I did this mostly as an experiment, feel free to continue where I left off.

In Meteor: How to use a npm library that should be pulled from a repository?

In my packages.json file, I have:
{
"sendwithus":"git+https://git#github.com/whalepath/sendwithus_nodejs.git#enable_testing_server"
}
because I need to use a forked ( and fixed version of the library). The above syntax works in straight node. How to do this in meteor?
This is the error I get:
=> Started proxy.
=> Errors prevented startup:
While reading package from `src/packages/npm-container`:
package.js:14:7: must declare exact version of dependency:
sendwithus#git+https://git#github.com/whalepath/sendwithus_nodejs.git#enable_testing_server
Update:
I tried removing the line and using meteor add to get the package included:
Failed:
meteor add sendwithus#2.9.1#https://github.com/whalepath/sendwithus_nodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4
=> Errors while parsing arguments:
While adding package sendwithus#2.9.1#https://github.com/whalepath/sendwithus_nodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4:
error: Package names can only contain lowercase ASCII alphanumerics, dash, dot, or colon, not "#".
Failed:
$ meteor add sendwithus#2.9.1_https://github.com/whalepath/sendwithus_nodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4
=> Errors while parsing arguments:
While adding package sendwithus#2.9.1_https://github.com/whalepath/sendwithus_nodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4:
error: Can't have two _ in version: 2.9.1_https://github.com/whalepath/sendwithus_nodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4
Failed:
$ meteor add server:sendwithus#2.9.1#https://github.com/whalepath/sendwithus_nodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4
=> Errors while parsing arguments:
While adding package server:sendwithus#2.9.1#https://github.com/whalepath/sendwithus_nodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4:
error: Package names can only contain lowercase ASCII alphanumerics, dash, dot, or colon, not "#".
Failed:
$ meteor add sendwithus#https://github.com/whalepath/sendwithusnodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4
=> Errors while parsing arguments:
While adding package sendwithus#https://github.com/whalepath/sendwithusnodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4:
error: Version string must look like semver (eg '1.2.3'), not 'https://github.com/whalepath/sendwithusnodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4'.
Based on the answer to this issue when I posted it to enter link description here, the only solution is to create a fake meteor package to wrap the new node library.
Npm.depends({sendwithus: "https://github.com/whalepath/sendwithusnodejs/commit/41b0d177f6eabf02de2daec9bb2b36daebbfbef4"});
To extend this answer:
Just to use a fork of a npm library requires:
packages/sendwithus/main.js:
SendWithUs = Npm.require('sendwithus');
2.
packages/sendwithus/package.js:
Package.describe({
summary: 'Wrapped sendwithus library',
version: '2.9.1',
name: 'sendwithus'
});
Npm.depends({sendwithus: "https://github.com/whalepath/sendwithus_nodejs/tarball/41b0d177f6eabf02de2daec9bb2b36daebbfbef4"});
Package.onUse(function(api){
api.addFiles('main.js', 'server');
api.export('SendWithUs');
});
removing the reference in the packages.json
meteor add sendwithus
Using the SendWithUs variable
Maybe this could be improved?

Add include dir for node gyp

I am deploying a node-js app to heroku that requires the npm package imagemagic-native.
I made the buildpack install libmagick++-dev and export the include path:
export INCLUDE_PATH="$BUILD_DIR/.apt/usr/include:$INCLUDE_PATH"
export CPATH="$INCLUDE_PATH"
export CPPPATH="$INCLUDE_PATH"
Upon installing the imagemagic-native package with npm install, node-gyp is invoked to compile it's binaries. However I get this error:
remote: > imagemagick-native#1.7.0 install /tmp/build_720834c3a32b65d69ae603d7c618e20f/node_modules/imagemagick-native
remote: > node-gyp rebuild
remote:
remote: make: Entering directory `/tmp/build_720834c3a32b65d69ae603d7c618e20f/node_modules/imagemagick-native/build'
remote: CXX(target) Release/obj.target/imagemagick/src/imagemagick.o
remote: In file included from ../src/imagemagick.cc:9:
remote: ../src/imagemagick.h:1:22: warning: Magick++.h: No such file or directory
This suggests that gcc doesn't see the header files for libmagick++, because $CCPATH is not available to it.
How can I make npm install add the path to the list of include_dirs that node-gyp uses?
More detail about my use case is here: Using Magick++ in a node.js application on heroku
Try:
setting the environment variable CXX=/path/to/g++ -Ipath/to/include
and then restarting the process. If you're using bash this is done by
export CXX="/path/to/g++ -Ipath/to/include"
/path/to/include being where the missing header Magick++.h is located
if that doesn't work you may manually have to set CXX to include the -I in the makefile at /tmp/build_720834c3a32b65d69ae603d7c618e20f/node_modules/imagemagick-native/build then cding into that directory and calling make.
I've spent some time trying to answer the same question. In the end, i've found the proper way to do this here. You need to set 'include_dirs' property in ~/.node-gyp/x.x.x/common.gypi.
This is how I've set the include dir on Mac OS to /opt/local/include/ (which is where all macports intalls go):
...
['OS=="mac"', {
'defines': ['_DARWIN_USE_64_BIT_INODE=1'],
'include_dirs': ['/opt/local/include'],
'xcode_settings': {
'ALWAYS_SEARCH_USER_PATHS': 'NO',
...
Though I'm not sure it's applicable for heroku environment.
You can also use the "include_dirs" option in your project binding.gyp file. Read more about available options on the format description page.
You can now do OTHER_CFLAGS='-I/usr/local/include' supposedly. See https://github.com/nickdesaulniers/node-nanomsg/pull/144

Resources