How to abstract next/image from next.js - node.js

I'm only using the next/image from Next.js. Is there a way to only install next/image module and not the entire Next.js module. I tried doing the following -
"next/image": "^10.0.5",
"next/link": "^10.0.5",
But after doing npm install I'm getting the following error -
$ npm install
npm ERR! code EINVALIDPACKAGENAME
npm ERR! Invalid package name "next/image": name can only contain URL-friendly characters
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\sugamxp\AppData\Roaming\npm-cache\_logs\2021-02-17T06_08_55_518Z-debug.log

There is no such package next/image, it is just a folder inside next package, so no, you cannot install it separately.
Moreover, you can't use it separately without NextJs because it relies on NextJs server to optimize images on demand. I guess, you would need to find another solution if you want image optimization.

Related

error npm ERR! code FETCH_ERROR npm ERR! errno FETCH_ERROR npm ERR! invalid json response body when installing reactjs

so im trying to learn ReactJS, but when i looked up to ReactJS docs, it says install with
npx create-react-app {project_name}
it also required nodejs & npm, i have installed node js latest version & npm. but when i run the command, it alwasy getting the same error, the error says
npm ERR! code FETCH_ERROR
npm ERR! errno FETCH_ERROR
npm ERR! invalid json response body at https://registry.npmjs.org/#types%2fsemver reason: Invalid response body while trying to fetch https://registry.npmjs.org/#types%2fsemver: EBUSY: resource busy or locked, rename 'C:\Users\AGUS\AppData\Local\npm-cache\_cacache\tmp\d5e89a99' -> 'C:\Users\AGUS\AppData\Local\npm-cache\_cacache\content-v2\sha512\5f\16\d22537befb8a38d3af73438bd2409a960900a502346287a0a0fa17784814bd2664f39eeb0107aa02ac292aeb51d7f52f4a90db5325d9b47bc8f5ce1538ca'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\AGUS\AppData\Local\npm-cache\_logs\2022-11-02T08_20_55_473Z-debug-0.log
i have searched up this problem but its not solved, always error.
please help me solve this problem :(
i have tried uninstall & reinstall node, still not working,
i tried npm cache clean --force & npm cache verify still not working, thank you:)
Try :
npm cache verify
npx create-react-app {project_name}
I had the same error and these steps solved it.
√ Would you like to use src/ directory with this project? Yes
√ Would you like to use experimental app/ directory with this project? Yes
√ What import alias would you like configured? ... #/*
and also ensure that no background apps are running

Add - - force flag to a dependency in package.json for a Reactjs project

I'm trying to deploy my front-end reactjs to Netlify, but I'm getting an error while installing react-ribbon package
I had a similar error while installing it locally and I had to force install it which worked and the package is working app(locally)
Now what I need is to make Netlify do the same thing (force install react-ribbon) but I'm not sure on how to go around to doing this
Is there some kind of flag I can add to the dependency in package.json so Netlify will recognize that this requires a force install
Or is there another similar ribbon package I can find that works similar to react-ribbon I can use instead without needing the force flag.
I tried multiple different ribbon packages but they all give me the same error while installing.
TL;DR: Specify environment variable NPM_CONFIG_LEGACY_PEER_DEPS = true in Netlify.
Long explanation:
First of all, you should understand what the error is about when you were installing react-ribbon.
That error is most likely something like this
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: react-ribbons#1.0.6
npm ERR! Found: react#18.2.0
npm ERR! node_modules/react
npm ERR! react#"18.2.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"^16.10.2" from react-ribbons#1.0.6
Basically, react-ribbons is expecting React 16, which I don't think you are using such an old version of React. So NPM believes react-ribbon is not compatible with your project, and prevents the installation.
Now by adding --force, which is self-explanatory enough, you are essentially asking NPM to install that regardless. And --legacy-peer-deps will more or less achieve the same thing and is less destructive.
And for the environment variable, this is simply one way of how NPM reads config. So if you set NPM_CONFIG_LEGACY_PEER_DEPS = true, NPM will automatically add the --legacy-peer-deps to the commands.
https://docs.npmjs.com/cli/v8/using-npm/config#environment-variables
And if you HAVE to use --force, which I don't recommend, you can do NPM_CONFIG_FORCE = true instead.

attempting to deploy meteor application. Fails when running NPM INSTALL

Sorry for the following wall of text.
So I've been using someone else's meteor app. (they open sourced it) It's currently un-built and I've been running it on dev-mode. It's a lot slower than expected and users are having issues connecting to my local machine. So I'm attempting to deploy the app by following: https://guide.meteor.com/deployment.html#deploying.
So I've been getting errors when trying to run npm i. My dad recommended me to run npm cache verify and try again, then npm cache clean as a last resort. Neither worked and I've still am getting errors. Although as soon as I tried again after running npm cache verify the error amount skyrocketed. I unfortunately don't have the errors I got before I cleared my cache but I have the current logs here: https://pastebin.com/dAcRnE9v But here is a snapshot:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fibers#2.0.2 install: `node build.js || nodejs build.js`
npm ERR! Exit status 1
npm ERR! Failed at the fibers#2.0.2 install script.
I honestly don't have any idea what todo. I've never worked with meteor before, nor the fibers module that's failing. I don't even know if this is the right place I should be asking for help.
I once had fibers npm package in my package.json which caused a similar error. Once I removed it everything built just fine.
You can't change Meteor's version of node - for compatibility reasons it bundles node/npm with Meteor to protect you. Just prefix all your npm/node commands with meteor like this:
meteor npm install
It won't use the node version (13.x) that you have installed

Having a hard time getting the Angular CLI server to start

I'm sure this isn't the first time you've run into this issue. I've researched over google, youtube, and stackoverflow on this issue, and it seems like this is an isolated incident. I don't know if it's an issue with versions, but I have been taking the Pluralsight course on Angular with Deborah K. I downloaded her Github version of the boilerplate starting files from https://github.com/DEborahK/Angular-GEttingStarted
I followed the course and installed the dependences from the package.json file using the integrated terminal. When I tried to run the script npm start which translates into ng serve -o I get this error message:
apm#0.0.0 start /Users/mateo/Desktop/projects/angular
ng serve -o
Cannot read property 'config' of null
TypeError: Cannot read property 'config' of null
at Class.run (/Users/mateo/Desktop/projects/angular/node_modules/#angular/cli/tasks/serve.js:21:63)
at check_port_1.checkPort.then.port (/Users/mateo/Desktop/projects/angular/node_modules/#angular/cli/commands/serve.js:110:26)
at
at process._tickCallback (internal/process/next_tick.js:118:7)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! apm#0.0.0 start: ng serve -o
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the apm#0.0.0 start 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! /Users/mateo/.npm/_logs/2018-03-26T22_16_46_516Z-debug.log
Sandys-MacBook-Pro:angular mateo$
Is there a best practice way to troubleshoot these kind of issues? Is there a better way to run these scripts or should I use a sandbox VMware linux install to run these fresh instead of running off my Macbook? Any help is appreciated! Thank you!
I was able to fix this issue by deleting all of the node_modules and re-installing the AngularCLI from scratch off of the Angular website.

Why am I getting Unexpected token '\u0000' when using npm install -g package

This is probably a Windows specific issue but I haven't found any information when googling this issue. I had been using ionic framework which relies on Cordova (or Phonegap). However, the problem is not specific to any of these packages. I see this error quite often. So, the error is when I run a command such as the following:
npm install -g cordova
However, I could substitute various other packages and get the same error. I'll paste the snippet (very brief) below of the error message. What is strange is that I had an ionic project working in that directory earlier. Then today it told me that ionic could not be found. My hunch is that this is a different issue than the main issue I am describing here.
I installed git bash so I do have a linux-like environment that I could try. I would just select Git Bash for a bash window with various bash commands. If there is an easier way to fix this for Windows users, please let me know. I have seen courses on Pluralsight where the instructors seem to be happily using npm with no problems. Also, when I use yeoman, I also at some point, in many cases, get the same error.
The error is
npm ERR! Failed to parse json
npm Unexpected token '\u0000' at 1:1
npm ERR!
npm ERR! ^
npm ERR! File: c:\Users\Bruce\AppData\Roaming\npm-cache\amdefine\1.0.0\package\package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! This is not a bug in npm
npm ERR! Tell the package author to fix their package.json file. JSON.parse.
Thanks in advance for any help/advice,
Bruce
Via this question on SO it could be that you just have to do:
npm cache clean.
But, also try the other methods suggested there like adding the registry option:
npm install <packagename> --registry http://registry.npmjs.org/.
Or, if you've been mingling with the package.json file by yourself, check if it's valid.

Resources