Error: "migrate dev is not a prisma command." when calling `npx prisma migrate dev --preview-feature` - migration

When I run the following command:
npx prisma migrate dev --preview-feature
I get the following error:
$ npx prisma migrate dev --preview-feature
npx: installed 600 in 26.334s
▸ migrate dev is not a prisma command.
▸ Perhaps you meant generate
▸ Run prisma help for a list of available commands.
Get in touch if you need help: https://slack.prisma.io
To get more detailed output, run $ set -x DEBUG "*"
(node:6096) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
(Use `node --trace-deprecation ...` to show where the warning was created)
However, the prisma migrate dev command should be available in the Prisma CLI. Why doesn't this work?

Okay I figured it out, I accidentally invoked the Prisma 1 CLI which is available as the prisma package on npm.
The way to fix this is to make sure that the Prisma 2 CLI which is available as the #prisma/cli package on npm is installed locally (see docs):
npm install #prisma/cli --save-dev
# or
yarn add #prisma/cli --dev
That way npx will execute the right binary from the local node_modules folder.
From the npx docs:
Executes <command> either from a local node_modules/.bin, or from a central cache, installing any packages needed in order for <command> to run.
By default, npx will check whether <command> exists in $PATH, or in the local project binaries, and execute that. If <command> is not found, it will be installed prior to execution.
Unless a --package option is specified, npx will try to guess the name of the binary to invoke depending on the specifier provided. All package specifiers understood by npm may be used with npx, including git specifiers, remote tarballs, local directories, or scoped packages.
If for some reason the local binary is not picked up, you can try to add the prisma script to your package.json:
{
"scripts": {
"prisma": "prisma"
}
}

Related

How to tell Expo to install npm dependencies with --legacy-peerdeps option?

I'm trying to build my Expo mobile app locally.
When Expo starts the [INSTALL_DEPENDENCIES] step, it performs npm install. But in my case, I'm aware of a legacy package I'm using which is causing some problems. So, this step is broken and the build is failing.
I want to configure Expo to perform npm install --legacy-peer-deps instead of npm install.
In my case, I have rn-pdf-reader-js#4.1.1 with Expo SDK 46.
Is this option configurable?
After looking a little bit, I figured it out using:
Create .npmrc file in the project root directory with:
legacy-peer-deps=true
However, another option is to run npm config set legacy-peer-deps true in eas-build-pre-install hook.
In package.json, add the following to scripts:
"eas-build-pre-install": "npm config set legacy-peer-deps true"

Understanding difference between npx and npm

I'm struggling to develop a deeper understanding of npx. So in particular the difference between running a commmand with npm and npx. I understand that npx can execute a package from a URL, just one local npm package etc.. But for example here:
npx lerna run start --scope frontend --stream
What is the difference between
npx lerna run start
and
npm lerna run start
?
NPM - Manages packages but doesn't make life easy executing any.
NPX - A tool for executing Node packages.
NPX comes bundled with NPM version 5.2+.
NPM by itself does not simply run any package. It doesn't run any package as a matter of fact. If you want to run a package using NPM, you must specify that package in your package.json file.
When executables are installed via NPM packages, NPM links to them:
1.local installs have "links" created at ./node_modules/.bin/ directory.
2.global installs have "links" created from the global bin/ directory (e.g. /usr/local/bin) on Linux or at %AppData%/npm on Windows.

How do I know the script options in a npm package?

For example, I installed tailwind CSS via npm by npm init && npm install tailwindcss. After that, I make a script in package.json like "build-css": "tailwindcss build src/styles.css -o public/styles.css"(I just copy-paste it from stuckoverflow). Now focus on -o, how a developer knows there is a -o option available for tailwind. I checked node-module/tailwindcss/script/build.js but there is no such thing that I currently understand( I mean, I found 0 clue). Pls give light on it. Do we have some standardization or unwritten rule that creator of npm package follow?
The scripts field in your package.json defines commands that are run with npm run in the context of npm. This allows you to use the command-line interface that are provided by different npm packages, without installing them globally. Many of these CLIs also expose a --help flag, or a help command.
To run the CLI from a npm package not installed globally, you may need to use npx. In your case, you can run:
npx tailwindcss
which tells you that there is a help command that gives you more information.
$ npx tailwindcss
tailwindcss 2.1.2
Usage:
tailwind <command> [options]
Commands:
help [command] More information about the command.
init [file] Creates Tailwind config file. Default: tailwind.config.js
build <file> [options] Compiles Tailwind CSS file.
If you are comfortable reading the source code in your node_modules folder, you can also find more information about these commands and the code that runs. To find where the CLI is defined, you can check node_modules/tailwindcss/package.json, which defines a bin key. In this case, it shows that the tailwindcss command comes from lib/cli.js. While the code is transformed, you can poke around and find lib/cli/commands/build.js, which contains the options for the build command.
const options = [{
usage: '-o, --output <file>',
description: 'Output file.'
}, {
usage: '-c, --config <file>',
description: 'Tailwind config file.'
}, {
usage: '--no-autoprefixer',
description: "Don't add vendor prefixes using autoprefixer."
}];
If the package is open source, you may be able to find the original, untransformed source online. In Tailwind's case, they have a Github repo where you can view the raw source for the build command.

On Mac M1, can't run scripts in package.json: - sh: <dependency>: command not found

I just got a Mac Mini M1 for personal use, and I'm trying to run a preexisting React app. I installed nodejs and npm successfully, and running npm install does add the node_modules folder correctly as far as I can tell; but whenever I run npm start or npm run <script>, I get an error. It seems that npm can't access any of the project's dependencies. I've tried this using the rosetta terminal as well with the same results.
For an example, I initialized a new React project with npx create-react-app test_app, then cded into it and ran npm start. I got:
test_repo#0.1.0 start
> react-scripts start
sh: react-scripts: command not found
How do I get these commands to run properly and launch the app?
Here's what I'm using for node and npm:
➜ test_repo npm -v
7.6.0
➜ test_repo node -v
v15.11.0
I found a (very) hacky solution for now. I'm no expert with npm, but what I discovered is that npm scripts refer to dependencies indirectly - for example, having a command that says
"test": "jest"
tells npm to look in node_modules/.bin for a file called jest and to run that.
the issue is something to do with npm understanding this. But it's possible to get around that by putting the address of each dependency in the script, for example:
"test" "node_modules/.bin/jest"
I was able to get things to build this way. If someone comes along with a better answer, please show me up :P

Yocto recipe fails to install npm package

I have a recipe that installed some NPM packages that worked on an older version of Yocto.
After upgrading to sumo, the recipe fails with the following error:
installnpmpackages/0.0.1-r0/temp/run.do_compile.7272: npm: not found
| WARNING: exit code 127 from a shell command.
I tried using the developer shell and NPM does work in that case.
The do_compile from the recipe:
do_compile() {
# Create a working directory
mkdir -p ${WORKDIR}/scratch
# changing the home directory to the working directory, the .npmrc will be created in this directory
export HOME=${WORKDIR}/scratch
# configure cache to be in working directory
npm set cache ${WORKDIR}/scratch/npm_cache
# clear local cache prior to each compile
npm cache clear
# compile and install node modules in source directory
cd ${WORKDIR}/scratch
npm --arch=${TARGET_ARCH} --verbose install node-gyp
npm --arch=${TARGET_ARCH} --verbose install connect
npm --arch=${TARGET_ARCH} --verbose install socket.io
#npm --arch=${TARGET_ARCH} --verbose install sqlite3
#npm --arch=${TARGET_ARCH} --verbose install serialport
npm --arch=${TARGET_ARCH} --verbose install express
npm --arch=${TARGET_ARCH} --verbose install csv
npm --arch=${TARGET_ARCH} --verbose install md5
# clear local cache before we package. No need to copy over all this cache stuff; just need the modules.
npm cache clear
}
Note sqlite3 and serialport are commented out as they did not work on the previous version.
What needs to be changed with sumo (vs morty) for NPM to function in a recipe?
Thank you in advance!
I found a simple solution.
I created individual recipes using devtool add.
Here is the command used to create a recipe for the serialport npm module:
devtool add "npm://registry.npmjs.org;name=serialport;version=7.1.4"
I'm answering to #Hsn comment as my account is new and I don't have 50 reputation.
If you are able to add a recipe with devtool and it worked, you can use devtool as well to finish working on the recipe and tell devtool in which meta you want to put the recipe like :
devtool finish recipe_name meta-destination
And in order to put it into your final OS rootfs, you need to add it to your image bb file, for example : image-dev.bb :
IMAGE_INSTALL_append += "recipe_name"
Make sure also that the meta which holds your recipe is present in your bblayers.conf.