Why Can't I Alias #bundled-es-modules/chai to chai? - node.js

Normally in NPM you can install a package under an alias, like so:
npm i alias#npm:real-package-name
For reference, here's where the aliasing feature was announced: https://npm.community/t/release-npm-6-9-0/5911
b7b54f2d1 413 #3 530 Add support for package aliases. This allows packages to be installed under a different directory than the package name listed in package.json, and adds a new dependency type to allow this to be done for registry dependencies. (#zkat 50)
This allows you to import/require the package using its alias instead of its real name:
import foo from 'alias'
However, when I try to do this with the ESM-bundled version of Chai:
npm i --save-dev chai#npm:bundled-es-modules/chai
I get the error "aliases only work for registry deps" ... but I can't find any information about what that error actually means at all. Here's the full stack trace:
25 verbose stack Error: aliases only work for registry deps
25 verbose stack at fromAlias (/usr/local/lib/node_modules/npm/node_modules/npm-package-arg/npa.js:270:11)
25 verbose stack at resolve (/usr/local/lib/node_modules/npm/node_modules/npm-package-arg/npa.js:70:12)
25 verbose stack at npa (/usr/local/lib/node_modules/npm/node_modules/npm-package-arg/npa.js:52:10)
25 verbose stack at /usr/local/lib/node_modules/npm/node_modules/#npmcli/arborist/lib/arborist/build-ideal-tree.js:406:31
25 verbose stack at Array.map (<anonymous>)
25 verbose stack at Arborist.[add] (/usr/local/lib/node_modules/npm/node_modules/#npmcli/arborist/lib/arborist/build-ideal-tree.js:405:28)
25 verbose stack at Arborist.[applyUserRequests] (/usr/local/lib/node_modules/npm/node_modules/#npmcli/arborist/lib/arborist/build-ideal-tree.js:390:23)
25 verbose stack at Arborist.buildIdealTree (/usr/local/lib/node_modules/npm/node_modules/#npmcli/arborist/lib/arborist/build-ideal-tree.js:207:37)
25 verbose stack at async Promise.all (index 1)
25 verbose stack at async Arborist.reify (/usr/local/lib/node_modules/npm/node_modules/#npmcli/arborist/lib/arborist/reify.js:123:5)
Can anyone explain what this error means, and why I can't alias that package (or if I can, what I'm doing wrong)?

I assume that you are wanting to alias this namespaced/scoped package #bundled-es-modules/chai during installation.
In which case add the # symbol prefix to the package <name> part of your install command. e.g.
npm i --save-dev chai#npm:#bundled-es-modules/chai
^
The npm-install docs provide the following synopsis for the alias command:
npm install <alias>#npm:<name>
Essentially, the # prefix for a scoped package is part of the package <name>.

Related

Stack Install/Build Packages

I have been trying for the past 3 days to learn how can I install packages to use in my haskell program.
I need a package called:
https://hackage.haskell.org/package/Chart-cairo
in order to start using:
https://github.com/timbod7/haskell-chart
I know its probably a silly question, but could someone explain how to install/build an haskel package with stack ?
Thank you!
To install package using stack simply type stack install packagename. Remember to register it in package.yaml as dependency in your project, otherwise it won't be visible.
In your case:
stack install Chart-cairo
and in package.yaml:
dependencies:
- ...
- Chart-cairo >= 1.9

stack install executable to a custom location

I usually do stack install <package-name> and Stack installs it in the location ~/.local/bin.
Is there a way for me to specify the destination location ?
You can use the --local-bin-path to specify your custom destination path. Demo:
$ stack install tldr --local-bin-path /home/sibi
Copying from /home/sibi/github/tldr-hs/.stack-work/install/x86_64-linux/lts-12.10/8.4.3/bin/tldr to /home/sibi/tldr
Copied executables to /home/sibi:
- tldr
Warning: Installation path /home/sibi not found on the PATH environment variable.
$ ls -lh /home/sibi/tldr
-rwxr-xr-x 1 sibi sibi 3.0M Dec 23 01:37 /home/sibi/tldr

haskell : stack install hfmt error

I'm totally new in haskell, and trying to install hfmt using stack.
stack install hfmt
but it shows
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for hfmt-0.2.0:
hindent-4.6.4 must match ==5.* (latest applicable is 5.2.5)
hlint-1.9.35 must match ==2.* (latest applicable is 2.0.15)
stylish-haskell-0.6.1.0 must match ==0.8.* (latest applicable is 0.8.1.0)
needed for unknown reason - stack invariant violated.
So, I tried to re-install hindent , hlint and stylish-haskell again.
However I couldn't find any command - stack upgrade or stack update.. even I failed to remove these packages.
Could you help install/update these package?
With reports like this, it's best to include the output of stack --version to know what version of the tool you're using. Also, how you installed Stack can be useful information.
As for hfmt: there's no version of it present in a Stackage snapshot, which you can see here:
https://www.stackage.org/package/hfmt
On my machine, I was able to build successfully against LTS 10.3, using this command:
stack install hfmt-0.2.0 --resolver lts-10.3

How do I build a package against multiple resolvers

How can I use stack to build and test a package against multiple resolvers?
Set the resolver from the command line, overriding whatever is in stack.yaml:
stack --resolver lts-X.Y [build|test|exec|...]
A more persistent solution is to have different .yaml configurations in your repository, that you can select using --stack-yaml
stack build # default is stack.yaml
stack --stack-yaml my-stack-lts-X.Y.yaml build
stack --stack-yaml my-stack-nightly-X-Y-Z.yaml build

WAR file generation error

I have successfully completed the bookstore application and It's been running so far. I wanted to package the application in an WAR file and have it run of a different machine/environment.
Environment:
Windows 7
JDK 8
Maven 3.3.9
NodeJS 5.3
I run the following command
mvn -Pprod package
Issue #1 - Bower execution failed, resolved by updating git config for https:// instead of git://
Issue #2 -Python related errors - Do I need to setup Python?
C:\Source\jhipster-projects\bookstore1\node_modules\utf-8-validate>if not defined npm_config_node_gyp
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
Issue #3 - PhantomJS related errors, I did update PhantomJS still with the same errors
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 46 of 46 SUCCESS (34.659 secs / 1.536 secs)
←[1A←[2KPhantomJS 1.9.8 (Windows 7 0.0.0): Executed 46 of 46 SUCCESS (34.659 secs / 1.536 secs)
Missing error handler on `socket`.
TypeError: sockets.forEach is not a function
at disconnectBrowsers (C:\Source\jhipster- projects\bookstore1\node_modules\karma\lib\server.js:314:13)
at null.<anonymous> (C:\Source\jhipster- projects\bookstore1\node_modules\karma\lib\server.js:291:7)
at emitTwo (events.js:92:20)
at emit (events.js:172:7)
at emitRunCompleteIfAllBrowsersDone (C:\Source\jhipster- projects\bookstore1\node_modules\karma\lib\server.js:256:12)
at null.<anonymous> (C:\Source\jhipster-projects\bookstore1\node_modules\karma\lib\server.js:278:9)
at emitTwo (events.js:92:20)
at emit (events.js:172:7)
at onComplete (C:\Source\jhipster-projects\bookstore1\node_modules\karma\lib\browser.js:142:13)
at Socket.<anonymous> (C:\Source\jhipster-projects\bookstore1\node_modules\karma\lib\events.js:13:22)
at emitTwo (events.js:92:20)
at Socket.emit (events.js:172:7)
at Socket.onevent (C:\Source\jhipster- projects\bookstore1\node_modules\socket.io\lib\socket.js:335:8)
at Socket.onpacket (C:\Source\jhipster- projects\bookstore1\node_modules\socket.io\lib\socket.js:295:12)
at Client.ondecoded (C:\Source\jhipster-projects\bookstore1\node_modules\socket.io\lib\client.js:193:14)
at Decoder.Emitter.emit (C:\Source\jhipster-projects\bookstore1\node_modules\component-emitter\index.js:134:20)
Thanks
It looks that this issue has been resolved a few hours ago in Karma v0.13.19:
https://github.com/karma-runner/karma/releases/tag/v0.13.19
https://github.com/jhipster/generator-jhipster/issues/2574
Not sure if you fixed it already, but Chris's answer was right. The Karma module needs to be updated in package.json for your project since it specifies which exact version to use, and won't use the newer version that you installed globally.
Change
"karma": "0.13.15",
to
"karma": "0.13.19",
then, run npm install

Resources