npm run build issue - 'zip' is not recognized - visual-studio-code

While trying to build my codebase on my computer with 'npm run build' I get this =>
'zip' is not recognized as an internal or external command,
operable program or batch file.
Is this an issue with my package.json file?
{
"name": "udacity-c2-image-filter",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"clean": "rimraf www/ || true",
"build": "npm run clean && tsc && copy package.json www\\package.json && mkdir www\\tmp\\ && cd www && zip -r Archive.zip . && cd ..",
"dev": "ts-node-dev --respawn --transpile-only ./src/server.ts"
},
"repository": {
"type": "git",
"url": "git+https://github.com/grutt/udacity-c2-image-filter.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/grutt/udacity-c2-image-filter/issues"
},
"homepage": "https://github.com/grutt/udacity-c2-image-filter#readme",
"devDependencies": {
"#types/bluebird": "^3.5.33",
"#types/express": "^4.17.0",
"#types/node": "^11.13.17",
"ts-node-dev": "^1.0.0-pre.40",
"tslint": "^5.18.0",
"typescript": "^3.5.3"
},
"dependencies": {
"express": "^4.17.1",
"jimp": "^0.16.1",
"rimraf": "^3.0.2",
"lodash": "^4.17.15"
}
}

So, I made changes to the build script in my package.json file, I used this instead "npm run clean && tsc && copy package.json www\\package.json && mkdir www\\tmp\\ && cd www && 7z.exe a Archive.zip . && cd .."
but alternatively using the command npm i npm-build-zip and changing the build script in my package.json to this "npm run clean && tsc && copy package.json www\\package.json && mkdir www\\tmp\\ && cd www && npm-build-zip --source=..\\www && cd .." also works.

Related

Why No Matching Commands when I init my first vscode extension?

I init my first vscode extension following this page.
Here is my steps:
npm install -g yo generator-code
yo code
And here is the package.json generated:
{
"name": "helloworld",
"displayName": "helloworld",
"description": "description helloworld",
"version": "0.0.1",
"engines": {
"vscode": "^1.72.0"
},
"categories": [
"Other"
],
"activationEvents": [
"onCommand:helloworld.helloWorld"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "helloworld.helloWorld",
"title": "Hello World"
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"#types/glob": "^8.0.0",
"#types/mocha": "^10.0.0",
"#types/node": "16.x",
"#types/vscode": "^1.72.0",
"#typescript-eslint/eslint-plugin": "^5.38.1",
"#typescript-eslint/parser": "^5.38.1",
"#vscode/test-electron": "^2.1.5",
"eslint": "^8.24.0",
"glob": "^8.0.3",
"mocha": "^10.0.0",
"typescript": "^4.8.4"
}
}
When I press H5 to debug, I got no command matched here:
I was stuck here for a while, where is my command??
I've encountered this just now as well. Make sure that engines.vscode in package.json matches the version of vscode you are running:
"engines": {
"vscode": "^1.73.0"
},
I guess the generator will use the latest version available, but you might not have upgraded yet. That was the case for me.
#tacospice pointed out exactly. in package.json, engines.vscode determines minimum version of VSCode. In my case, yo created extension template which set minimum VSCode version(1.74.0) newer than working VSCode(1.70.0). Check Help -> About -> version with package.json.

How do I overcome parcel-bundler error create-near-app

Hi I have created a near app with a react frontend but when I try to install #date-io/date-fns I get an error:
Cannot read property 'length' of undefined
at lineCounter (C:\Users\Simon Palmer\Documents\Programming\bimstarter-app\node_modules\parcel-bundler\src\utils\lineCounter.js:3:30)
at JSPackager.writeModule (C:\Users\Simon Palmer\Documents\Programming\bimstarter-app\node_modules\parcel-bundler\src\packagers\JSPackager.js:127:60)
at async JSPackager.addAsset (C:\Users\Simon Palmer\Documents\Programming\bimstarter-app\node_modules\parcel-bundler\src\packagers\JSPackager.js:88:5)
at async Bundle._addDeps (C:\Users\Simon Palmer\Documents\Programming\bimstarter-app\node_modules\parcel-bundler\src\Bundle.js:250:5)
at async Bundle._package (C:\Users\Simon Palmer\Documents\Programming\bimstarter-app\node_modules\parcel-bundler\src\Bundle.js:219:7)
at async Promise.all (index 0)
at async Bundle.package (C:\Users\Simon Palmer\Documents\Programming\bimstarter-app\node_modules\parcel-bundler\src\Bundle.js:202:5)
at async Promise.all (index 2)
at async Bundle.package (C:\Users\Simon Palmer\Documents\Programming\bimstarter-app\node_modules\parcel-bundler\src\Bundle.js:202:5)
at async Bundler.bundle (C:\Users\Simon Palmer\Documents\Programming\bimstarter-app\node_modules\parcel-bundler\src\Bundler.js:325:27)
my package.json file is as follows
{
"name": "bimstarter-app",
"version": "0.1.0",
"license": "UNLICENSED",
"scripts": {
"build": "npm run build:contract && npm run build:web",
"build:contract": "node contract/compile.js",
"build:contract:debug": "node contract/compile.js --debug",
"build:web": "parcel build src/index.html --public-url ./",
"dev:deploy:contract": "near dev-deploy",
"deploy:contract": "near deploy",
"deploy:pages": "gh-pages -d dist/",
"deploy": "npm run build && npm run deploy:contract && npm run deploy:pages",
"prestart": "npm run build:contract:debug && npm run dev:deploy:contract",
"start": "echo The app is starting! It will automatically open in your browser when ready && env-cmd -f ./neardev/dev-account.env parcel src/index.html --open",
"dev": "nodemon --watch contract -e ts --exec \"npm run start\"",
"test": "npm run build:contract:debug && cd contract && npm run test && cd .. && jest test --runInBand"
},
"devDependencies": {
"#babel/core": "~7.14.0",
"#babel/preset-env": "~7.14.0",
"#babel/preset-react": "~7.13.13",
"babel-jest": "~26.6.2",
"env-cmd": "~10.1.0",
"gh-pages": "~3.1.0",
"jest": "~26.6.2",
"jest-environment-node": "~26.6.2",
"near-cli": "~2.1.1",
"nodemon": "~2.0.3",
"parcel-bundler": "^1.12.5",
"react-test-renderer": "~17.0.1",
"shelljs": "~0.8.4"
},
"dependencies": {
"#date-io/date-fns": "^2.13.1",
"#emotion/react": "^11.9.0",
"#emotion/styled": "^11.8.1",
"#mui/icons-material": "^5.6.2",
"#mui/material": "^5.6.2",
"#mui/x-date-pickers": "^5.0.0-alpha.1",
"near-api-js": "~0.43.1",
"react": "~17.0.1",
"react-dom": "~17.0.1",
"react-router-dom": "6",
"regenerator-runtime": "~0.13.5"
},
"resolutions": {
"#babel/preset-env": "7.13.8"
},
"jest": {
"moduleNameMapper": {
"\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/src/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/src/__mocks__/fileMock.js"
},
"setupFiles": [
"<rootDir>/src/jest.init.js"
],
"testEnvironment": "near-cli/test_environment",
"testPathIgnorePatterns": [
"<rootDir>/contract/",
"<rootDir>/node_modules/"
]
}
This happened also when I was trying to install react bootstrap.
To build again does the parcel-bundler need to be upgraded to parcel as it has been depreciated? If so how do I do this without effecting the rest of the near app code dependencies?

dotenv not working after transcompile with Babel

I have code reading .env using dotenv that is working in dev but after transcompiling with Babel the values from process.env are undefined. I created a sample program to illustrate the problem which is below.
If I'm in projectRoot and run
npm run start-w
then
console.log(process.env.VAR1)
prints the value 'var1Val'
However, if I do
npm run build
cd dist
node index.js
the value of VAR1 is 'undefined'.
index.js
import 'dotenv/config'
console.log('VAR1', process.env.VAR1)
.env
VAR1=var1val
VAR2=var2val
VAR3=var3val
.babelrc
{
"presets": ["#babel/preset-env"],
"plugins": [
"#babel/plugin-transform-runtime",
]
}
package.json
{
"name": "dotenv.node-babel",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"#babel/runtime": "^7.4.3",
"dotenv": "^7.0.0"
},
"devDependencies": {
"#babel/cli": "^7.4.3",
"#babel/core": "^7.4.3",
"#babel/node": "^7.2.2",
"#babel/plugin-transform-runtime": "^7.4.3",
"#babel/preset-env": "^7.4.3",
"#types/dotenv": "^6.1.1",
"nodemon": "^1.18.11",
"rimraf": "^2.6.3"
},
"scripts": {
"clean-dist": "rimraf dist",
"build": "npm run-script clean-dist && babel . -d dist --ignore node_modules",
"start": "babel-node index.js",
"start-w": "NODE_ENV=devLocal nodemon --exec babel-node index.js"
},
"author": "",
"license": "ISC"
}
If you do not have a .env file in your build directory, try creating one. I guess that's why the environment variable is undefined.

Tests are passing, coverage is not showing

I'm trying to get nyc ava and babel to all place nice together. I was having an issue where async / await branches were showing as not covered, so this was working, I'm having trouble integrating the babel-plugin-istanbul plugin for tests.
I have two files in the project, src/index.js and src/test.js.
{
"name": "example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "ava",
"coverage": "NODE_ENV=test nyc npm run test",
"report": "nyc report --reporter=html",
"report:open": "open ./coverage/index.html",
"cover": "npm run coverage && npm run report && npm run report:open"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel-runtime": "^6.26.0",
"bluebird": "^3.5.0",
"lodash": "^4.17.4"
},
"devDependencies": {
"ava": "^0.22.0",
"babel-cli": "^6.26.0",
"babel-plugin-istanbul": "^4.1.4",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.0",
"babel-register": "^6.26.0",
"nyc": "^11.2.1",
"sinon": "^3.2.1",
"testdouble": "^3.2.4"
},
"babel": {
"presets": ["env"],
"plugins": ["transform-runtime"],
"env": {
"test": {
"plugins": ["istanbul"]
}
}
},
"ava": {
"require": ["babel-register"],
"babel": "inherit"
},
"nyc": {
"sourceMap": false,
"instrument": false
}
}
Here's whats running:
> example#1.0.0 coverage /Users/me/Desktop/example
> NODE_ENV=test nyc npm run test
> example#1.0.0 test /Users/me/Desktop/example
> ava
11 passed
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files | Unknown | Unknown | Unknown | Unknown | |
----------|----------|----------|----------|----------|----------------|
> example#1.0.0 report /Users/me/Desktop/example
> nyc report --reporter=html
> example#1.0.0 report:open /Users/em/Desktop/example
> open ./coverage/index.html
Why isn't src/index.js showing in the coverage?
Try to move test.js under some test folder test/test.js

How to use glob file specifications for stylus on the command line?

I have many directories. In many of those there is a .styl file. I want to create a .css file within that same directory for each directory containing a .styl file. Additionally, whenever the .styl file is updated, I'd like the respective .css file to update.
I'm trying to create a script in my package.json to accomplish this, but without much luck. I don't know how to specify an output filename dynamically either, so I realize that part of the code bellow is incorrect. Before tackling that (potentially) I have an error I'll describe after the code. I'm open to an alternative output, I just want my .styl files to stay in their modules and whatever .css file(s) that are output to update automatically.
Here's the relevant commands from the "scripts" part of my package.json:
"styles": "stylus -u autoprefixer-stylus ./src/**/*.styl -o ./src/css/",
"styles:watch": "stylus -u autoprefixer-stylus -w ./src/**/*.styl -o ./src/css/",
"watch": "concurrently --names 'webpack, stylus' --prefix name 'npm run start' 'npm run styles:watch'"
Here's the error:
[ stylus] > stylus -u autoprefixer-stylus -w ./src/**/*.styl -o ./src/css/
[ stylus]
[ stylus] /Users/itsme/Projects/todo-react/node_modules/stylus/bin/stylus:641
[ stylus] if (err) throw err;
[ stylus] ^
[ stylus]
[ stylus] Error: ENOENT: no such file or directory, stat './src/**/*.styl'
Full package.json if it's helpful:
{
"name": "todo",
"version": "0.1.0",
"private": true,
"devDependencies": {
"autoprefixer-stylus": "^0.13.0",
"concurrently": "^3.1.0",
"react-scripts": "0.8.5",
"stylus": "^0.54.5"
},
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-router": "^4.0.0-alpha.6"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"styles": "stylus -u autoprefixer-stylus ./src/**/*.styl -o ./src/css/",
"styles:watch": "stylus -u autoprefixer-stylus -w ./src/**/*.styl -o ./src/css/",
"watch": "concurrently --names 'webpack, stylus' --prefix name 'npm run start' 'npm run styles:watch'"
}
}