ES Module alternative of popular packages - es6-modules

Is there a centralized repository where I can find ES module (ESM) alternatives for popular npm packages?
I'm looking for a mapping like:
'lodash' => 'lodash-es'
'react' => '#pika/react'
'react-dom' => '#pika/react-dom'
// etc

you can use jspm instead of npm
jspm is a es module package manager
https://jspm.org/docs/guide

Related

require('react') vs require('React')

The following code in external node_modules is not working:
var _react = require('react');
But:
var _react = require('React');
works. Now I have a problem that in some node_modules it is required with 'react', and then I get this error:
Uncaught Error: Cannot find module 'react'
I am using gulp as build tool.
What can I do so that both requires will work?
Do you have 'React' added in your package.json ?
If not, add: "react": "17.0.2" (or another React version)
Try running the command:
npm install
And try again
Require is not a React api. Try this syntax:
import React from 'react'

The required JS dependency "readable-stream/writable.js" is not available, it was required by "node_modules/stream-browserify/index.js"

I am getting this error when trying to build a Clojurescript project with shadow-cljs. I've tried looking for syntax errors as described here but I can get the same the error with a single line and a single import although not all imports cause the same error.
This compiles:
(ns campfire.core)
(defn init [] (println "ok"))
This doesn't:
(ns campfire.core
(:require ["bugout" :as b]))
(defn init [] (println "ok"))
The output from the above example is:
shadow-cljs - config: /home/ru/Projects/campfire/shadow-cljs.edn
shadow-cljs - HTTP server available at http://localhost:3000
shadow-cljs - server version: 2.11.18 running at http://localhost:9630
shadow-cljs - nREPL server started on port 8777
shadow-cljs - watching build :frontend
[:frontend] Configuring build.
[:frontend] Compiling ...
[:frontend] Build failure:
The required JS dependency "readable-stream/writable.js" is not available, it was required by "node_modules/stream-browserify/index.js".
Dependency Trace:
campfire/core.cljs
node_modules/bugout/index.js
node_modules/bs58check/index.js
node_modules/create-hash/browser.js
node_modules/cipher-base/index.js
node_modules/stream-browserify/index.js
Searched for npm packages in:
/home/ru/Projects/campfire/node_modules
See: https://shadow-cljs.github.io/docs/UsersGuide.html#npm-install
package.json
{
"name": "campfire",
"version": "0.0.1",
"private": true,
"scripts": {
"build": "shadow-cljs release frontend"
},
"devDependencies": {
"shadow-cljs": "2.11.18"
},
"dependencies": {
"bugout": "^0.0.10",
"webtorrent": "^0.114.1"
}
}
shadow-cljs.edn
{:source-paths
["src/dev"
"src/main"
"src/test"]
:dependencies
[]
:dev-http {3000 "public"}
:nrepl {:port 8777}
:builds
{:frontend
{:target :browser
:modules {:main {:init-fn campfire.core/init}}}}}
I've seen similar build errors that were fixed by clearing .shadow-cljs etc and rebuilding but nothing like that seems to be helping. I'm new to shadow so apologies if this is something obvious. Does anyone have any idea what's going on here?
Update
So it looks like what's happening is that stream-browserify 2.0.2 requires readable stream ^2.0.2 which npm installs in the nested node_modules folder. Elsewhere readable-stream 3.6.0 is being installed in top level node_modules. Shadow is trying to resolve writer.js against the 3.6.0 version of readable stream instead of the 2.0.2 version.
Confusingly though, stream-browserify isn't a dependency of cipher-base as given in the dependency trace but of node-libs-browser which is itself a dependency of shadow-cljs.
Is it possible that this is a bug in shadow or is it expected behaviour?
Update 2
I've created an example repo that replicates what I'm seeing as simply as I can here.
Did you actually install the shadow-cljs dependency in the project? Does the directory node_modules/shadow-cljs exist?
I see it listed in devDependencies so it should be installed but it might not be if you never actually called npm install in the project or npm is set to production mode which won't install devDependencies. All of this is part of the node-libs-browser package which seems to be missing as well and should have been installed due to being a dependency of shadow-cljs.
Based on the link in your first error message, it says to npm install whatever's missing.
If you didn't run npm install, that by itself will install what's in your package.json.
If that's not the issue, then npm i readable-stream may help.

Upgrading ngx-bootstrap 3.0.1 to 4.0.1

While Upgrading from ngx bootstrap 3.0.1 to 4.0.1 am getting the following error.Replaced the node_modules, package.json still getting the same errors.
Angular Version :
Angular 6,
Typescript: 2.7.2.
Errors:
ERROR in node_modules/ngx-bootstrap/chronos/utils/type-checks.d.ts(8,62): error TS2304: Cannot find name 'Extract'.
node_modules/ngx-bootstrap/datepicker/reducer/bs-datepicker.actions.d.ts(5,33): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/ngx-bootstrap/timepicker/reducer/bs-datepicker.actions.d.ts(4,33): error TS1039: Initializers are not allowed in ambient contexts.
Errors in the image
I have encounter this error when I was using ngx-editor to implement rich text editor in Angular
This error occurs due to older version of Angular and rxjs, In my case I was using Angular 6 and rxjs 6.0.0, then I have updated it to Angular 7 and rxjs 6.2.0 by using below commands (Typescript will also be updated to typescript 2.9.2)
ng update rxjs#~6.2.0
ng update #angular/cli #angular/core
Note: If you are getting below warning
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
and you want to ignore this warning (fsevents#1.2.7:) you can use below command
npm i -f
After this, I have uninstall ngx-bootstrap and ngx-editor, then first install dependency packages and then reinstall ngx-bootstrap and ngx-editor, as mentioned below steps.
npm i ajv#^6.9.1 --save
npm i font-awesome#^4.7.0 --save
npm i angular-font-awesome
npm install ngx-bootstrap --save
npm install ngx-editor --save
At last, you need to check if HttpClientModule and other packages are properly imported in app.module.ts
import { NgxEditorModule } from 'ngx-editor';
import { AngularFontAwesomeModule } from 'angular-font-awesome';
import { TooltipModule } from 'ngx-bootstrap/tooltip';
import { HttpClientModule } from '#angular/common/http';
imports: [
BrowserModule,
AppRoutingModule,
NgxEditorModule,
AngularFontAwesomeModule,
TooltipModule.forRoot(),
HttpClientModule
],
Now it is resolved, In addition you can able to use rich text editor by using ngx-editor
Thanks
the Solution for this error is the same to the above, change the followings versions in package.json.
"bootstrap": "4.1.3",
"font-awesome": "4.7.0",
"ngx-bootstrap": "3.1.1",
"ngx-editor": "4.0.0",
"rxjs": "6.3.3",
remove the node_module and package-lock.json and than install npm:
npm install.
Fix it in files
"\node_modules\ngx-bootstrap\datepicker\reducer\bs-datepicker.actions.d.ts"
From
static readonly CALCULATE = "[datepicker] calculate dates matrix";
To
static readonly CALCULATE : "[datepicker] calculate dates matrix";
Solution for this error is change the Bootstrap version (4.0.0 to 3.0.0) and remove the ^ in package.json (i.e "rxjs": "^6.0.0" to "rxjs": "6.0.0", and "rxjs-compat": "^6.2.2" to "rxjs-compat": "6.2.2",).
if you want bootstrap 4 version than try to change the rxjs and rxjs-compat (As i inform in above line).and remove the node_module and package-lock.json and than install npm.

Babel dependency not resolved in react app created using "create-react-app" utility

I have created a react-app using create-react-app utility but when I import a node module then it gives me error stating :
./node_modules/#nross/react-vega/src/VegaLite.js
Module parse failed: Unexpected token (17:2)
You may need an appropriate loader to handle this file type.
| onParseError,
| children,
| ...otherProps
| }) => {
| const adjustedSpec = { ...spec };
And when I import babel-loader into the file where I am importing the node module then it is giving me the error:-
Failed to compile.
./node_modules/babel-core/lib/helpers/resolve.js
Module not found: Can't resolve 'module' in 'C:\VegaDemo\my-app\node_modules\babel-core\lib\helpers'.
You need to eject in order to customize the boilerplate.
Simply run
npm run eject
Or
yarn run eject
If you use yarn.
Then, install your npm module and run
npm run install
Without eject, the boilerplate is locked up.

laravel blade templates minifier using laravel-mix # laravel 5.4

As of laravel 5.4, they are no longer using gulp but rather webpack, and they no longer use laravel-elixir but rather a new package they called laravel-mix, now I use a package called laravel-elixir-blade-minifier which minifies laravel-blade templates, how do I use it with now with laravel-mix? I mean, I'm getting confused here.
you can try: https://github.com/hiseanchang/laravel-mix-template-minifier
npm install --save-dev laravel-mix-template-minifier
// webpack.mix.js
let mix = require('laravel-mix');
mix.minTemplate = require('laravel-mix-template-minifier')
if (mix.inProduction()) {
mix.minTemplate('storage/framework/views/*.php', 'storage/framework/views/')
}