hanazuki / node-jsonnet Goto Github PK
View Code? Open in Web Editor NEWlibjsonnet binding for Node.js
Home Page: https://www.npmjs.com/package/@hanazuki/node-jsonnet
License: MIT License
libjsonnet binding for Node.js
Home Page: https://www.npmjs.com/package/@hanazuki/node-jsonnet
License: MIT License
Code like std.parseJson("$%^&")
will result with this log in console:
Something went wrong during jsonnet_evaluate_snippet, please report this: [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: 'd'
and process will get killed.
Instead promise should be rejected. so one can handle this in catch
instead of process shutting down.
related google/jsonnet#680
The following program must terminate:
const { Jsonnet } = require("@hanazuki/node-jsonnet");
const jsonnet = new Jsonnet();
jsonnet.nativeCallback("id", (x) => x, "x");
I created a react application from template with:
yarn create react-app --template cra-template-typescript my-app
Then I added "@hanazuki/node-jsonnet": "^0.3.0"
as dependency to package.json
code sample of the readme to App.tsx
, run yarn install
then yarn start
. The served page indicates the following errors:
TypeError: Error.captureStackTrace is not a function
getFileName
node_modules/bindings/bindings.js:169
166 | };
167 |
168 | // run the 'prepareStackTrace' function above
> 169 | Error.captureStackTrace(dummy);
| ^ 170 | dummy.stack;
171 |
172 | // cleanup
bindings
node_modules/bindings/bindings.js:82
79 |
80 | // Get the module root
81 | if (!opts.module_root) {
> 82 | opts.module_root = exports.getRoot(exports.getFileName());
| ^ 83 | }
84 |
85 | // Ensure the given bindings name ends with .node
./node_modules/@hanazuki/node-jsonnet/lib/index.js
node_modules/@hanazuki/node-jsonnet/lib/index.js:2
1 | /*! SPDX-License-Identifier: MIT */
> 2 | module.exports.Jsonnet = require('bindings')('node-jsonnet');
3 |
__webpack_require__
/home/philippe/temp/react/my-app/webpack/bootstrap:784
781 | };
782 |
783 | // Execute the module function
> 784 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 785 |
786 | // Flag the module as loaded
787 | module.l = true;
fn
/home/philippe/temp/react/my-app/webpack/bootstrap:150
147 | );
148 | hotCurrentParents = [];
149 | }
> 150 | return __webpack_require__(request);
| ^ 151 | };
152 | var ObjectFactory = function ObjectFactory(name) {
153 | return {
./src/App.tsx
http://localhost:3000/static/js/main.chunk.js:109:99
__webpack_require__
/home/philippe/temp/react/my-app/webpack/bootstrap:784
781 | };
782 |
783 | // Execute the module function
> 784 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 785 |
786 | // Flag the module as loaded
787 | module.l = true;
fn
/home/philippe/temp/react/my-app/webpack/bootstrap:150
147 | );
148 | hotCurrentParents = [];
149 | }
> 150 | return __webpack_require__(request);
| ^ 151 | };
152 | var ObjectFactory = function ObjectFactory(name) {
153 | return {
./src/index.tsx
http://localhost:3000/static/js/main.chunk.js:253:81
__webpack_require__
/home/philippe/temp/react/my-app/webpack/bootstrap:784
781 | };
782 |
783 | // Execute the module function
> 784 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 785 |
786 | // Flag the module as loaded
787 | module.l = true;
fn
/home/philippe/temp/react/my-app/webpack/bootstrap:150
147 | );
148 | hotCurrentParents = [];
149 | }
> 150 | return __webpack_require__(request);
| ^ 151 | };
152 | var ObjectFactory = function ObjectFactory(name) {
153 | return {
1
http://localhost:3000/static/js/main.chunk.js:406:18
__webpack_require__
/home/philippe/temp/react/my-app/webpack/bootstrap:784
781 | };
782 |
783 | // Execute the module function
> 784 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 785 |
786 | // Flag the module as loaded
787 | module.l = true;
checkDeferredModules
/home/philippe/temp/react/my-app/webpack/bootstrap:45
42 | }
43 | if(fulfilled) {
44 | deferredModules.splice(i--, 1);
> 45 | result = __webpack_require__(__webpack_require__.s = deferredModule[0]);
| ^ 46 | }
47 | }
48 |
webpackJsonpCallback
/home/philippe/temp/react/my-app/webpack/bootstrap:32
29 | deferredModules.push.apply(deferredModules, executeModules || []);
30 |
31 | // run deferred modules when all chunks ready
> 32 | return checkDeferredModules();
| ^ 33 | };
34 | function checkDeferredModules() {
35 | var result;
(anonymous function)
http://localhost:3000/static/js/main.chunk.js:1:65
node_modules/@hanazuki/node-jsonnet/node_modules
where empty. I run yarn install
from that directory but it still doesn't work.
How can I use node-jsonnet
in my application?
Thank you.
node version: v13.13.0
cmake version: 3.10.2
yarn version: 1.22.4
When trying to use the import statement from the example:
import {Jsonnet} from '@hanazuki/node-jsonnet';
I get this error:
import {Jsonnet} from '@hanazuki/node-jsonnet';
^^^^^^^
SyntaxError: The requested module '@hanazuki/node-jsonnet' is expected to be of type CommonJS, which does not support named exports. CommonJS modules can be imported by importing the default export.
For example:
import pkg from '@hanazuki/node-jsonnet';
const {Jsonnet} = pkg;
Using nodejs v12.19.0
[ 71%] Built target libjsonnet
Scanning dependencies of target node-jsonnet
[ 76%] Building CXX object CMakeFiles/node-jsonnet.dir/src/JsonValueConverter.cpp.o
In file included from /usr/src/app/node_modules/@hanazuki/node-jsonnet/src/JsonValueConverter.hpp:5:0,
from /usr/src/app/node_modules/@hanazuki/node-jsonnet/src/JsonValueConverter.cpp:4:
/usr/src/app/node_modules/@hanazuki/node-jsonnet/src/JsonnetVm.hpp:10:20: fatal error: optional: No such file or directory
#include <optional>
^
compilation terminated.
CMakeFiles/node-jsonnet.dir/build.make:82: recipe for target 'CMakeFiles/node-jsonnet.dir/src/JsonValueConverter.cpp.o' failed
make[2]: *** [CMakeFiles/node-jsonnet.dir/src/JsonValueConverter.cpp.o] Error 1
make[1]: *** [CMakeFiles/node-jsonnet.dir/all] Error 2
CMakeFiles/Makefile2:288: recipe for target 'CMakeFiles/node-jsonnet.dir/all' failed
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2
Running npm install in an empty project yields the following output:
C:\dev\jsonnet-test>npm install @hanazuki/node-jsonnet
> @hanazuki/[email protected] install C:\dev\jsonnet-test\node_modules\@hanazuki\node-jsonnet
> cmake-js build --CDCMAKE_EXPORT_COMPILE_COMMANDS=1
[
'C:\\Program Files\\nodejs\\node.exe',
'C:\\dev\\jsonnet-test\\node_modules\\cmake-js\\bin\\cmake-js',
'build',
'--CDCMAKE_EXPORT_COMPILE_COMMANDS=1'
]
info TOOL Using Visual Studio 16 2019 generator.
info CMD CONFIGURE
info RUN [
info RUN 'cmake',
info RUN 'C:\\dev\\jsonnet-test\\node_modules\\@hanazuki\\node-jsonnet',
info RUN '--no-warn-unused-cli',
info RUN '-G',
info RUN 'Visual Studio 16 2019',
info RUN '-A',
info RUN 'x64',
info RUN '-DCMAKE_JS_VERSION=6.2.1',
info RUN '-DCMAKE_BUILD_TYPE=Release',
info RUN '-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=C:\\dev\\jsonnet-test\\node_modules\\@hanazuki\\node-jsonnet\\build',
info RUN '-DCMAKE_JS_INC=<REDACTED>\\.cmake-js\\node-x64\\v14.17.0\\include\\node',
info RUN '-DCMAKE_JS_SRC=C:/dev/jsonnet-test/node_modules/cmake-js/lib/cpp/win_delay_load_hook.cc',
info RUN '-DNODE_RUNTIME=node',
info RUN '-DNODE_RUNTIMEVERSION=14.17.0',
info RUN '-DNODE_ARCH=x64',
info RUN '-DCMAKE_JS_LIB=<REDACTED>\\.cmake-js\\node-x64\\v14.17.0\\win-x64\\node.lib',
info RUN '-DCMAKE_EXPORT_COMPILE_COMMANDS=1',
info RUN '-DCMAKE_SHARED_LINKER_FLAGS=/DELAYLOAD:NODE.EXE'
info RUN ]
Not searching for unused variables given on the command line.
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
-- The C compiler identification is MSVC 19.29.30040.0
-- The CXX compiler identification is MSVC 19.29.30040.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Deprecation Warning at third_party/jsonnet/CMakeLists.txt:2 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
CMake Error at third_party/jsonnet/CMakeLists.txt:43 (message):
Compiler MSVC not supported
-- Configuring incomplete, errors occurred!
See also "C:/dev/jsonnet-test/node_modules/@hanazuki/node-jsonnet/build/CMakeFiles/CMakeOutput.log".
ERR! OMG Process terminated: 1
npm WARN @hanazuki/[email protected] requires a peer of @types/node@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @hanazuki/[email protected] install: `cmake-js build --CDCMAKE_EXPORT_COMPILE_COMMANDS=1`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @hanazuki/[email protected] install 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! <REDACTED>\AppData\Roaming\npm-cache\_logs\2021-08-10T14_14_02_481Z-debug.log
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.