What if I installed devDependency package as dependency, do I need to reinstall it as devDependency? - visual-studio-code

Most of the time, when I need to install a package as a devDependency but I forget to add --save-dev command thus this installation is final to dependency.
What I do:
"dependencies": {
"#types/express": "^4.11.1"
},
"devDependencies": {
}
But my requirement is:
"dependencies": {
},
"devDependencies": {
"#types/express": "^4.11.1"
}
Now, do I need to reinstall it as devDependency or cut and paste in devDependency is OK?

Related

Sanity Deployment on Vercel Issue: Cannot find module 'sanity' even though package is installed

So i'm trying to deploy sanity/nextjs on vercel. It runs fine locally but for the production build I keep getting the same error.
Here's the main error:
> build
> next build
info - Linting and checking validity of types...
Failed to compile.
./sanity/sanity.config.ts:1:28
Type error: Cannot find module 'sanity' or its corresponding type declarations.
> 1 | import {defineConfig} from 'sanity'
| ^
2 | import {deskTool} from 'sanity/desk'
3 | import {visionTool} from '#sanity/vision'
4 | import {schemaTypes} from './schemas'
Error: Command "npm run build" exited with 1
My sanity package.json:
{
"name": "nft-drop",
"private": true,
"version": "1.0.0",
"main": "package.json",
"license": "UNLICENSED",
"scripts": {
"dev": "sanity dev",
"start": "sanity start",
"build": "sanity build",
"deploy": "sanity deploy",
"deploy-graphql": "sanity graphql deploy"
},
"keywords": [
"sanity"
],
"dependencies": {
"#sanity/vision": "^3.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-is": "^18.2.0",
"sanity": "^3.0.0",
"styled-components": "^5.2.0"
},
"devDependencies": {
"#sanity/cli": "^3.2.3",
"#sanity/eslint-config-studio": "^2.0.1",
"eslint": "^8.6.0",
"prettier": "^2.8.3",
"typescript": "^4.0.0"
},
"prettier": {
"semi": false,
"printWidth": 100,
"bracketSpacing": false,
"singleQuote": true
}
}
My main folder package.json:
{
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"#next/font": "^13.1.2",
"#sanity/image-url": "^1.0.1",
"#thirdweb-dev/react": "^3.6.9",
"#thirdweb-dev/sdk": "^3.6.9",
"ethers": "^5.7.2",
"next": "latest",
"next-sanity": "^4.0.6",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"#sanity/cli": "^3.2.3",
"#types/node": "18.11.3",
"#types/react": "18.0.21",
"#types/react-dom": "18.0.6",
"autoprefixer": "^10.4.12",
"postcss": "^8.4.18",
"tailwindcss": "^3.2.4",
"typescript": "4.9.4"
}
}
Thanks for your help.
I've checked that I have the 'sanity' package installed. I've added the recommended 'vercel.json' file and I also have the #sanity/cli installed. I've checked my local env setup to make sure that was also on vercel.
Maybe i've overinstalled the sanity packages in trying to solve it?
This is my first time using sanity, nextjs, and vercel so I've run out of ideas and haven't found the same issue answered elsewhere yet.
I had this issue as well, and it seems to be related to Sanity v3 which only came out a month ago - I rolled back to sanity v2 and it fixed the deployment issue
You can try to add .vercelignore in the root file and add sanity in there to ignore the whole folder
The fix is to move your sanity client config file (aka wherever you have your .env variables setup - in my case: sanity.ts) into a lib folder in the root directory. If the file itself is in the root directory, it will not build.
Updating the import statement from
import {defineConfig} from 'sanity'
to
import {defineConfig} from 'sanity/lib/exports'
worked for me.

Why is tsc command not found in child package in yarn workspace?

I'm using yarn version 3.2.4. I have a package.json in my root that looks like this:
{
"scripts": {
"compile": "tsc --build",
},
"devDependencies": {
"typescript": "^4.8.4"
}
}
In packages/foo, I have this package.json
{
"scripts": {
"compile": "tsc --build"
},
"devDependencies": {
}
}
When I run yarn compile from the root, tsc compiles correctly. But this fails:
cd packages/foo
yarn compile
command not found: tsc
If I change the child packages to include typescript as a devDependency then it works.
Why aren't the devDependencies inherited from the parent package.json?

'import' and 'export' may appear only with 'sourceType: module when import "#solana/web3.js"

I am going to use solanaweb3 on babelrc project.
When I run npm start I am getting .
I have gone through many posts on github and stackoverflow.
npm install -g browserify
npm install --save-dev browserify babelify babel-preset-es2015 babel-preset-stage-0 babel-preset-env babel-preset-react
npm install #babel/core --save
What is solution?
Here is my package.json content.
"scripts": {
"start": "budo src/index.js"
},
"dependencies": {
"#babel/runtime": "^7.14.8",
"#solana/web3.js": "^1.29.2",
"babel-core": "7.0.0-bridge.0"
},
"devDependencies": {
"#babel/core": "^7.15.5",
"#babel/plugin-transform-runtime": "^7.15.0",
"#babel/preset-env": "^7.15.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babelify": "^10.0.0",
"browserify": "^16.5.2",
"budo": "^11.6.4"
},
"browserify": {
"transform": [
[
"babelify",
{
"presets": [
"#babel/preset-env"
]
}
]
]
}
}

How to use mongoose-double package

I have mongoDB and mongoose library installed. Now if I want to use the mongoose-double package, does it require to be installed separately before? I want to store latitude and longitude data in double.
Below is my package.json file.
{
"version": "0.0.1",
"private": true,
"dependencies": {
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.4",
"debug": "^4.1.1",
"express": "^4.17.1",
"jade": "^1.11.0",
"mongodb": "^3.3.2",
"mongoose": "^5.6.11",
"monk": "^7.0.0",
"morgan": "^1.9.1",
"request": "^2.88.0",
"serve-favicon": "^2.5.0"
}
}
Yes, you need to install the mongoose-double package before using that. You can install it using:
npm i mongoose-double
And then initialize your mongoose object like this:
var mongoose = require('mongoose')
require('mongoose-double')(mongoose);
Hope this works for you.

Plugin 0 specified in babel-preset-es2015 provided an invalid property of _c

Getting above error with below configuration, commenting passPerPreset removes the error however. Is there any configuration missing ?
.babelrc :
{
"passPerPreset": true,
"presets": [{
"plugins": [
"./build/babelRelayPlugin",
"transform-runtime",
"transform-es2015-classes"
]
}, "es2015", "stage-0", "react"],
"env": {
"development": {
"presets": ["react-hmre"]
}
}
}
package.json :
"babel-cli": "^6.5.1",
"babel-core": "^6.5.2",
"babel-eslint": "^4.1.8",
"babel-loader": "^6.2.2",
"babel-plugin-react-transform": "^2.0.0",
"babel-plugin-transform-es2015-classes": "^6.5.2",
"babel-plugin-transform-runtime": "^6.5.2",
"babel-polyfill": "^6.5.0",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"babel-preset-react-hmre": "^1.1.0",
"babel-preset-stage-0": "^6.5.0",
"babel-relay-plugin": "^0.7.0",
"babel-runtime": "^6.5.0",
Webpack :
module: {
loaders: [
{
loader: "babel-loader",
include: [
path.resolve(__dirname, "app"),
],
test: /\.jsx?$/,
query: {
plugins: ['transform-runtime'],
presets: ['react', 'es2015', 'stage-0'],
}
},
]
},
Error : babel-node start
Module build failed: Error: Plugin 0 specified in "/Users/my/demo/node_modules/babel-preset-es2015/index.js" provided an invalid property of "_c"
What worked for me was:
rm -rf node_modules
npm prune
npm cache clear
npm cache clean
npm i
Upgrading babel-core and babel-loader fixed this for me.
npm install --save babel-core#latest babel-loader#latest
I think that there might be contention between what you've specified in .babelrc and what you've configured in babel-loader.
Can you try to remove the query from your Webpack config?
I had the same problem, but removing and rebuilding node_modules as Alex suggested didn't help in my case.
It turned out that there was some version mismatch with may packages. When I deleted all the dependencies and devDependencies from package.json and added them again by npm i -S or npm i -D respectively, everything started to work again.
Clearing my node_modules etc didn't work. However, commenting-out passPerPreset did the trick. TBH I'm not really sure what that option does, but most of the google hits on it are bug reports, so I'm fine so long as it works.
// babelrc
{
//"passPerPreset": true,
"presets": [
"stage-0",
"react-app"
],
"plugins": [
"transform-runtime",
"syntax-async-functions",
"transform-decorators-legacy",
"transform-class-properties",
"react-relay"
]
}
Updating my npm version solved this problem.