binding.gyp doesn't see included library - node-gyp

I'm playing around with node-gyp and I am trying to add a library, muParser to some of the example code by adding a folder libraries at the same level as hello.cc and simply adding #include <muParser.h> to hello.cc.
libraries has the following structure:
-include - with files such as muParser.h
-lib - with a single file libmuparser.a
The problem is that my binding.gyp file doesn't do what I think it should as for the following 2 variants, relative and absolute paths, I get the same error - ../hello.cc:3:10: fatal error: 'muParser.h' file not found when I npm install:
{
"targets": [
{
"target_name": "hello",
"sources": [ "hello.cc" ],
"include_dirs": [
"../libraries/include/"
],
"libraries": [
"-llibmuparser', '-L../libraries/lib/"
],
}
]
}
{
"targets": [
{
"target_name": "hello",
"sources": [ "hello.cc" ],
"include_dirs": [
"<(module_root_dir)/../libraries/include/"
],
"libraries": [
"<(module_root_dir)/../libraries/lib/libmuparser.a"
],
}
]
}
Can anybody explain how I include this library?

I create binding.gyp file manually under the path C:\Users\Administrator with following content:
{
"targets": [
{
"target_name": "binding",
"sources": [ "build/Release/binding.node" ]
}
]
}
After that, I run node-gyp rebuild command and the issue is solved.

Related

React - StoryBook - Error importing my components from node_modules

I have a project in React that contains quite a few components and I wanted to install StoryBook to be able to consult them.
For this I have installed StoryBook as a project outside my main project, leaving the folder structure as follows:
c:\development\MyProject
c:\development\StoryBook
Inside StoryBook I have added the following 'import' inside the Button.stories.jsx file that manages the buttons section that comes by default in the installation.
import SmallButton from 'MyProject/Buttons/SmallButton';
For this to work and to be able to import my component I have created a symbolic link inside the node_modules folder inside the StoryBook project.
c:\development\StoryBook\node_modules\MyProject <== symbolic link to c:\development\MyProject\src
When I start StoryBook with yarn storyboook it finds my component file but gives the following error that I can't resolve:
ERROR in ../MyProject/src/components/VSNButtons/SmallButton/index.js 10:12
Module parse failed: Unexpected token (10:12)
File was processed with these loaders:
* ./node_modules/#storybook/preset-create-react-app/node_modules/#pmmmwh/react-refresh-webpack-plugin
/loader/index.js
You may need an additional loader to handle the result of these loaders.
| const className = "ep-action " + (this.props.disabled ? "disabled " : " ") + (this.props.className || "");
| return (
> <span className={className} onClick={this.props.onClickHandle}>
| <span>
| <i className={"ep-action zmdi " + this.props.iconClass}></i>
# ./src/stories/atoms/buttons/Button.stories.jsx 150:0-58
# ./src sync ^\.(?:(?:^|[\\/]|(?:(?:(?!(?:^|[\\/])\.).)*?)[\\/])(?!\.)(?=.)[^\\/]*?\.stories\.(js|jsx|ts|tsx))$
# ./generated-stories-entry.js
# multi ./node_modules/#storybook/preset-create-react-app/node_modules/#pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js ./node_modules/#storybook/preset-create-react-app/node_modules/#pmmmwh/react-refresh-webpack-plugin/client/ErrorOverlayEntry.js ./nod
e_modules/#storybook/core-server/node_modules/#storybook/core-client/dist/esm/globals/polyfills.js ./node_modules/#storybook/core-server/node_modules/#storybook/core-client/dist/esm/globals/globals.js ./node_modules/webpack-hot-middleware/client.js?reload=true&quiet=fal
se&noInfo=undefined ./storybook-init-framework-entry.js ./node_modules/#storybook/addon-docs/dist/esm/frameworks/common/config.js-generated-config-entry.js ./node_modules/#storybook/addon-docs/dist/esm/frameworks/react/config.js-generated-config-entry.js ./node_modules/
#storybook/react/dist/esm/client/preview/config-generated-config-entry.js ./node_modules/#storybook/addon-links/dist/esm/preset/addDecorator.js-generated-config-entry.js ./node_modules/#storybook/addon-actions/dist/esm/preset/addDecorator.js-generated-config-entry.js ./
node_modules/#storybook/addon-actions/dist/esm/preset/addArgs.js-generated-config-entry.js ./node_modules/#storybook/addon-backgrounds/dist/esm/preset/addDecorator.js-generated-config-entry.js ./node_modules/#storybook/addon-backgrounds/dist/esm/preset/addParameter.js-g
enerated-config-entry.js ./node_modules/#storybook/addon-measure/dist/esm/preset/addDecorator.js-generated-config-entry.js ./node_modules/#storybook/addon-outline/dist/esm/preset/addDecorator.js-generated-config-entry.js ./node_modules/#storybook/addon-interactions/dist
/esm/preset/argsEnhancers.js-generated-config-entry.js ./.storybook/preview.js-generated-config-entry.js ./generated-stories-entry.js
**File Configuration of StoryBook (main.js) **
module.exports = {
stories: [
"../src/**/*.stories.mdx",
"../src/**/*.stories.#(js|jsx|ts|tsx)"
],
staticDirs: ["../public"],
addons: [
"#storybook/addon-links",
"#storybook/addon-essentials",
"#storybook/preset-create-react-app",
"#storybook/addon-interactions",
],
features: {
postcss: false
},
framework: "#storybook/react",
core: {
builder: "webpack4",
}
};
And .babelrc of StoryBook
{
"sourceType": "unambiguous",
"presets": [
[
"#babel/preset-env",
{
"shippedProposals": true,
"loose": true
}
],
"#babel/preset-typescript"
],
"plugins": [
"#babel/plugin-transform-shorthand-properties",
"#babel/plugin-transform-block-scoping",
[
"#babel/plugin-proposal-decorators",
{
"legacy": true
}
],
[
"#babel/plugin-proposal-class-properties",
{
"loose": true
}
],
[
"#babel/plugin-proposal-private-methods",
{
"loose": true
}
],
"#babel/plugin-proposal-export-default-from",
"#babel/plugin-syntax-dynamic-import",
[
"#babel/plugin-proposal-object-rest-spread",
{
"loose": true,
"useBuiltIns": true
}
],
"#babel/plugin-transform-classes",
"#babel/plugin-transform-arrow-functions",
"#babel/plugin-transform-parameters",
"#babel/plugin-transform-destructuring",
"#babel/plugin-transform-spread",
"#babel/plugin-transform-for-of",
"babel-plugin-macros",
"#babel/plugin-proposal-optional-chaining",
"#babel/plugin-proposal-nullish-coalescing-operator",
[
"babel-plugin-polyfill-corejs3",
{
"method": "usage-global",
"absoluteImports": "core-js",
"version": "3.18.3"
}
]
]
}
Does anyone know what would be the solution to apply to solve this problem?
Or maybe it's because I can't import components from other projects.
Thank you very much.
PD: Sorry my english, I used GoogleTranslate to help me.

Babel fails with class-validator in NX Library

I have an NX Typescript library which pulls in 'class-validators'.
The initial error I've ran into is
Support for the experimental syntax 'decorators-legacy' isn't currently enabled
So I've added this to my babel.config.json:
"plugins": [
[
"#babel/plugin-proposal-decorators",
{
"legacy": true
}
]
]
The next error I get is
Unexpected token, expected "{"
........
node_modules/#nrwl/web/src/utils/web-babel-loader.js)
in all my TypeScript files. I'm assuming babel is expecting JavaScript, so I've added
"presets": [
"#babel/preset-typescript"
],
To my babel.config.json. Now the issue I get with any class that uses class-validator's decorators (#IsDefined(), #IsNotNull(), etc...)
Module parse failed: Unexpected token (10:8)
File was processed with these loaders:
* ../../../node_modules/#nrwl/web/src/utils/web-babel-loader.js
You may need an additional loader to handle the result of these loaders.
I'm using an NX Workspace, and this is a plain TypeScript library... I'm not 100% sure what's going wrong here. When I run my NestJS server with this library it compiles and runs fine. But for some reason when I run the ReactJS Application, it fails with this error.
Any help is greatly appreciated!
EDIT:
Working babel.config.json
{
"babelrcRoots": [
"*"
],
"presets": [
"#babel/preset-typescript",
"#babel/preset-env"
],
"plugins": [
[
"#babel/plugin-proposal-decorators",
{
"legacy": true
}
],
[
"#babel/plugin-proposal-class-properties",
{
"legacy": true
}
],
[
"#babel/plugin-transform-runtime"
]
]
}

I have a watch.json file but it doesn't ignore folders

{
"install": {
"include": [
"^package\\.json$",
"^\\.env$"
]
},
"restart": {
"exclude": [
"^public/",
"^dist/"
],
"include": [
"\\.js$",
"\\.json"
]
},
"throttle": 999999999999
}
This currently ignores the index.js.
But I need it to ignore the commands/ folder too, so the folder and all of its commands inside. so that our bot doesn't keep refreshing/restarting.
You'd need to add ^commands/ to your exclude list under restart.

React-Native 0.57: 'Can't find variable: require' with metro-react-native-babel-preset

I started a multiplatform project with code sharing between react-native and react-js.
So I have a webpack setup for browser/Electron, and a react-native 0.57 setup for Android/iOS.
The problem I'm having right now is the following:
Can't find variable: require
It might be a very bald question, but do I need anything else? I read, that React-native should support require by itself, but couldn't find anything related to this setup yet.
.babelrc
{"presets": ["module:metro-react-native-babel-preset"]}
I'm also using #babel/polyfill and #babel/runtime on browser side, but I wonder if they would interfere.
Got the solution, my .babelrc was okay, but the packager cached the very first wrong one so I had to start the packager as:
react-native start --reset-cache
After looking at below github issue it looks like the issue is caused by corejs option #babel/plugin-transform-runtime, So replace it by #babel/polyfil
https://github.com/facebook/react-native/issues/21048
.babelrc config for ref
{
"presets": [
"module:metro-react-native-babel-preset",
],
"plugins": [
"react-require",
[
"module-resolver",
{
"root": [
"./src",
"./assets"
],
"alias": {
"app": "./src",
"assets": "./assets"
}
}
],
[
"babel-plugin-require-context-polyfill",
{
"alias": {
"app": "./src"
}
}
],
"#babel/plugin-proposal-export-default-from",
"#babel/plugin-proposal-export-namespace-from",
"#babel/plugin-transform-flow-strip-types",
[
"#babel/plugin-proposal-decorators",
{
"legacy": true
}
],
[
"#babel/plugin-proposal-class-properties",
{
"loose": false
}
],
[
"#babel/plugin-transform-runtime",
{
}
],
],
"sourceMaps": true
}
Install Babel polyfill 7 "#babel/polyfill": "^7.0.0"
And import that in App component
import '#babel/polyfill'
It seems that react-native start --reset-cache works.

Why my omp.h path isn't being recognized?

My problems console in Visual Studio Code is showing me the following up message:
#include errors detected. Please update your includePath. InteliSense features for this translation unit
cannot open source file "omp.h"
This message is being showed even after I linked the path of omp.h after found it with:
find /usr -name omp.h
My c_cpp_properties.json file:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/omp.h",
"/usr/include/c++/7.2.0",
"/usr/include/c++/7.2.0/x86_64-pc-linux-gnu",
"/usr/local/include",
"/usr/lib/clang/5.0.0/include",
"/usr/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/omp.h",
"/usr/include/c++/7.2.0",
"/usr/include/c++/7.2.0/x86_64-pc-linux-gnu",
"/usr/local/include",
"/usr/lib/clang/5.0.0/include",
"/usr/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
]
}
What am I missing out? And how to fix it?
I've fixed changing the path to:
"/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/"
Removing the omp.h file.

Resources