How to correctly setup a local ReasonMl / Bucklescript dependencies - npm

New to ReasonML, and I probably don't understand the bucklescript documentation for setting up
a module as a dependency.
ReasonML project, compiles correctly, with the file MyUtils.re in directory ~/ml/myutils/src.
second ReasonML project in ~/ml/project2/src, file Demo.re starts with
open MyUtils;
I installed the first project: I tried both
npm install -g
inside ~/ml/myutils, and
npm install ../myutils --save
inside ~/ml/project2
the module looks installed globally :
npm list -g | grep myutils
├─┬ myutils#0.1.3 -> /home/user/ml/myutils
and also locally
npm list | grep myutils
└─┬ myutils#0.1.3 -> /home/user/ml/myutils
bsconfig.json
"bs-dependencies": [
"#glennsl/bs-json",
"myutils"
],
package.json
"dependencies": {
"#glennsl/bs-json": "^5.0.2",
"myutils": "file:../myutils"
}
but npm run build :
We've found a bug for you!
/home/user/ml/project2/src/Demo.re 2:6-12
1 │
2 │ open MyUtils;
3 │
4 │
The module or file MyUtils can't be found.
- If it's a third-party dependency:
- Did you list it in bsconfig.json?
- Did you run `bsb` instead of `bsb -make-world`
(latter builds third-parties)?
- Did you include the file's directory in bsconfig.json?
I tried adding file:../myutils to bsconfig.json: no change
What am I doing wrong?

#gash go check bsconfig.json of myutils.
Set "namespace": false
If Myutils namespace is true. it will probably create extra module layer for you.
Something like MyUtils.MyUtils

Related

How to exclude a specific version of a package that a project dependency uses and override it with a different one?

I'm running into an issue with my npm mirror.
It appears to be lagging behind. Currently, my Jenkins build fails, because it does not see scheduler#^0.20.2, which was published about 20 hours ago.
Weirdly enough, npm ls scheduler returns empty, so I'm not sure what package is requesting it, but I need to, at least for now, somehow specify scheduler#^0.20.1 to be used in my project.
Is there a way to do this? I want to ensure that whichever package it is that depends on scheduler#^0.20.2 will have only scheduler#^0.20.1 available to it.
I just run
$ npm install scheduler#0.20.1
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN nm#1.0.0 No description
npm WARN nm#1.0.0 No repository field.
+ scheduler#0.20.1
added 4 packages from 3 contributors and audited 4 packages in 2.939s
found 0 vulnerabilities
then check
$ npm ls
nm#1.0.0 /home/daniil/
└─┬ scheduler#0.20.1
├─┬ loose-envify#1.4.0
│ └── js-tokens#4.0.0
└── object-assign#4.1.1
Editing package.json would probably have worked when you need force deep-lying module version:
{
"scripts": {
"preinstall": "npx npm-force-resolutions"
},
"resolutions": {
"scheduler": "^0.20.1"
},
}
I solved this way potential vulnerabilities in my repo

webpack a module that contains node_modules

Question
I want to make changes to an open source JavaScript library. Using webpack and npm and keeping everything local, what options do I have to make changes to a local module and import it into project in place of an public npm module downloaded from the registry? The local module and consuming app will also be source controlled under two separate git repositories.
Problem
I am testing this within an Aurelia app, but I think it is a webpack and npm problem. I have an app called my-app which has a dependency on aurelia-binding. I wish to make local changes to aurelia-binding and push them to a fork in GitHub. My project structure looks like this:
└───my-app
├───.git
├───dist
├───node_modules
│ └───aurelia-binding
| ├───.git
│ ├───dist
│ └───src
└───src
When built and run, everything works as expected. To make a change to aurelia-binding and test them in my-app, I need to install its dependencies and build it. This results in a structure like this:
└───my-app
├───dist
├───node_modules
│ └───aurelia-binding
| ├───.git
│ ├───dist
| ├───node_modules
| | └───dependencies...
│ └───src
└───src
When the node_modules are installed on the dependency, webpack throws an error at runtime. The error may look like an issue with the aurlia module, but I do not believe this is the case.
Unhandled rejection Error: Error invoking SVGAnalyzer. Check the inner error for details.
------------------------------------------------
Inner Error:
Message: __WEBPACK_IMPORTED_MODULE_1_aurelia_pal__.a.createElement is not a function
I have also tried this using npm link with the library cloned next to my-app instead of within in but got the same result.
I used the following addition to the webpack.config.js to be able to use npm/yarn linked packages. It forces webpack to resolve the modules only using the main node_modules and not the "nearest" ones.
resolve: {
extensions: [".ts", ".js"],
symlinks: false,
modules: ["ClientApp", path.resolve('node_modules')],
}
Where "ClientApp" is the folder where my aurelia app is located. The symlinks parameter is used to prevent webpack from resolving the symlinked path to an absolute path.
A word of warning, with this setup you circumvent version checking by npm so you are responsible for linking a compatible version.

React Native cannot find entry file in any of the roots

Description
Cloned a repo to a new computer and getting the following error:
swipes#0.0.1 start C:\a\swipes-api\mobile
node node_modules/react-native/local-cli/cli.js start
Scanning 722 folders for symlinks in C:\a\swipes-api\mobile\node_modules (30ms)
┌────────────────────────────────────────────────────────────────────────────┐
│ Running packager on port 8081. │
│ │
│ Keep this packager running while developing on any JS projects. Feel │
│ free to close this tab and run your own packager instance if you │
│ prefer. │
│ │
│ https://github.com/facebook/react-native │
│ │
└────────────────────────────────────────────────────────────────────────────┘
Looking for JS files in
C:\a\swipes-api\mobile
error: bundling: NotFoundError: Cannot find entry file index.android.js in any of the roots: ["C:\\a\\swipes-api\\mobile"]
at DependencyGraph._getAbsolutePath (C:/a/swipes-api/mobile/node_modules/react-native/packager/src/node-haste/DependencyGraph.js:280:11)
at DependencyGraph.getDependencies (C:/a/swipes-api/mobile/node_modules/react-native/packager/src/node-haste/DependencyGraph.js:218:26)
at Resolver.getDependencies (C:/a/swipes-api/mobile/node_modules/react-native/packager/src/Resolver/index.js:107:27)
at C:/a/swipes-api/mobile/node_modules/react-native/packager/src/Bundler/index.js:591:37
at next (native)
at step (C:\a\swipes-api\mobile\node_modules\react-native\packager\src\Bundler\index.js:12:445)
at C:\a\swipes-api\mobile\node_modules\react-native\packager\src\Bundler\index.js:12:605
at process._tickCallback (internal/process/next_tick.js:103:7)
Bundling `index.android.js` 0.0% (0/1), failed.
The path is correct where it's searching from. I've been stuck with this for the whole day now.
Is this somehow because there are double backslashes in the path to the index file?
npm start -- --reset-cache results in the same error.
Running yarn start after react-native run-android results in the same issue as well.
npm run start -- --root C:\a\swipes-api\mobile - No result.
This does not seem to be connected to the previous issue in the RN 0.45.0.
Additional Information
React Native version: 0.45.1
Platform: Android
Development Operating System: Windows
Edit:
All new projects with react-native init result in the same issue. Seems to be an issue with the config of my computer or npm, but I can't seem to track down why this happens.
Any ideas?
I have this and some like this error on windows.
Updating the npm and the node helped me on this issue.
currently i have:
C:\usr\Far>node -v && npm -v
v6.11.1
3.10.10
Many trials to run was not successful at all until I do not update. Anyway some errors like this appear time to time. Just restart. Also helpful to do before restart (but may be not need, just restart):
sh -c 'rm -rf $TMP/react*'
npm cache clean
Where $TMP is your system tmp directory, (check for existence react temp files there)
If you add or update some packages or some like that modifications concerning node_modules directory need to do also:
rm -rf node_modules && npm install

Share node_modules installation between sub-projects, while maintaining separate package.json files

I have the following folder structure:
project
├───components
│ ├───component-one
│ │ package.json
│ │
│ └───component-two
│ │ package.json
│ │
│ └───node_modules
├───node_modules
└───package.json
Project root project folder contains package.json and is intended to have various infrastructural modules installed (Gulp, for example, as the build is centralized).
Each component under components folder is eventually, after build and whatnot, is deployed somewhere to be consumed by an application - using the usual npm install from folder or tarball. For that reason, each component must maintain its own dependencies in its own package.json.
Going the trivial route, installing node_modules into each of the component folders would lead to a crazy amount of duplication, as there may be 100s of components, each installing mostly the same dependencies.
Ideally I would like to:
run, for example, npm install -D <module> in component-one folder
have package.json in that folder updated with the <module>
have <module> installed in the project folder
This can be achieved, to some extent, running (on Windows, in this case) mklink /D node_modules ..\..\node_modules from component-one to create a symlink.
However, symlinks are fragile and finicky, so I'd like to avoid that solution.
Is there an npm solution, via npm link or something that I am missing?

Why are my Yeoman generators installing in the wrong place?

I have a problem with Yeoman generators. They install just fine if I run "npm install [generator-name] -g". However when I try to run "yo [generator-name] yeoman can't seem to find the generator. Neither is it listed among my other generators if I just run "yo". I've tried a bunch of generators and the result is always the same.
After a bit of bit of investigation I found that the downloaded generator is placed in
/usr/local/lib/node_modules/
But my other generators are placed in
/usr/local/lib/share/npm/lib/node_modules/
Here is an image of how it looks on my machine http://i.imgur.com/DxWTYHb.png, I'm running OSX in case that matters. Looks like something is wrong to me - but I cannot figure it out.
Not sure if this helps, but brew doctor and $NODE_PATH return nothing while $PATH returns:
-bash:
/usr/local/share/npm/bin:
/Users/marcus/.rvm/gems/ruby-2.0.0-p247/bin:
/Users/marcus/.rvm/gems/ruby-2.0.0-p247#global/bin:
/Users/marcus/.rvm/rubies/ruby-2.0.0-p247/bin:
/Users/marcus/.rvm/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/usr/local/bin:
/usr/local/git/bin: No such file or directory
UPDATE
I tried what Eddie Monge Jr suggested and now my angular generator works fine. However when I installed another generator (chrome-extension) yeoman insists that it's not installed/found.
When I run ls $(npm config get prefix)/lib/node_modules I get this:
bower generator-mocha
generator-angular grunt-cli
generator-chrome-extension npm
generator-karma yo
And npm list -g returns this (I cut out a lot of generic stuff)
/usr/local/lib
├─┬ bower#1.2.3
├─┬ generator-angular#0.4.0
│ └─┬ yeoman-generator#0.13.3
├─┬ generator-chrome-extension#0.2.3
│ └─┬ yeoman-generator#0.12.3
├─┬ generator-karma#0.5.0
│ └─┬ yeoman-generator#0.13.3
├─┬ generator-mocha#0.1.1
│ └─┬ yeoman-generator#0.10.5
├─┬ grunt-cli#0.1.9
├─┬ npm#1.3.5
└─┬ yo#1.0.0
The strange part for me is if I run yo --help I get a strange list of generators
[?] What would you like to do?
[ ] Run the Angular generator
[ ] Run the Foundation generator
[ ] Run the H5bp generator
[X] Run the Mocha generator
[ ] Run the Webapp generator
[ ] Run the Karma generator
[ ] Update your generators
[ ] Install a generator
[ ] Find some help
[ ] Get me out of here!
I tried installing Yeoman on an Ubuntu precise32 vagrant vm. I ran into the same problem: Yeoman did not find the generators I installed, although there were no errors during the installation of these generators. Files were in place and permissions seemed alright.
The above solutions didn't work for me.
I ran
yo doctor
to see what was wrong, and as it turned out, the following was the problem:
[Yeoman Doctor] Uh oh, I found potential errors on your machine
---------------
[Error] NPM root value is not in your NODE_PATH
[info]
NODE_PATH = /usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
NPM root = /home/vagrant/npm/lib/node_modules
[Fix] Append the NPM root value to your NODE_PATH variable
Add this line to your .bashrc
export NODE_PATH=$NODE_PATH:/home/vagrant/npm/lib/node_modules
Or run this command
echo "export NODE_PATH=$NODE_PATH:/home/vagrant/npm/lib/node_modules" >> ~/.bashrc && source ~/.bashrc
The fix suggested by the Yeoman Doctor worked as advertised.
I hit this issue and I'm hoping it will help someone.
I believe upgrading NPM caused this initial issue for me.
/usr/local/lib/node_modules
Was the location of a lot of my modules in the past. Since upgrading node at some point, the directory became
/usr/local/share/npm/lib/node_modules
When I would run new installations such as:
npm install -g grunt-cli
I since I run grunt from the command line it wouldn't 'find' it (that's because it wasn't in my new node_modules dir). I set up this up in my .bash_profile:
export PATH=$PATH:/usr/local/share/npm/bin
Now I am pointing to the new node_modules directory
So all the new npm modules I install find the right location: /usr/local/share/npm/lib/node_modules
But not yo
I ran a which yo and my path was
/usr/local/bin/yo
This binary was pointing to the OLD node_modules installation #
/usr/local/lib/node_modules
My solution was to do this
rm /usr/local/bin/yo
npm remove -g yo
The old reference to yo is gone for keeps, now I can do
npm install -g yo
This will add it to the new node_modules location
/usr/local/share/npm/lib/node_modules
and now the new 'yo' references the proper node_modules installation base
source ~/.bash_profile
then we can see yo is referenced from the proper spot
which yo
/usr/local/share/npm/bin/yo
all future generators will be placed in the proper node_modules directory and yo will be able to find them without a problem!
I uninstalled yeoman entirely, then re-installed it
npm remove -g yo
npm install -g yo
This fixed my problem with missing angular generators.
Sounds like your npm may be out of whack. Check where things are installed:
npm config get prefix
Is that where you expected the packages to install? Is that where they are currently installed?
To list whats in there:
ls $(npm config get prefix)/lib/node_modules
That will list out the globally installed npm packages.
npm list -g
Will list the currently installed things. Make sure yo and the generators are listed at the top level.
To remove the yo stuff and start over:
npm remove -g yo generator-* yeoman-generator
npm install -g yo generator-angular
That should fix things.