Git Bash and webpack - node.js

Hello guys I'm trying to learn Webpack I've been following some tutorials and I've run into some problems. I've installed webpack locally in folder I am working in with npm install webpack --save-dev. I made two JS scripts and I wanted to bundle them and I've tried following command webpack script-1.js /.bundle.js in WindowsPowerShell (I'm using Windows 7). Now this made the following error
webpack is not recognized as an internal or external command operable program or batch file
So then I installed webpack globally, and when I used the same command in PowerShell (I have opened it as an admin), it made bundle.js file but not in the directory I was working in, but in C:
Now after this failure I've decided to try using git bash. First I've tried this command webpack script-1.js /.bundle.js and got the following error
bash: webpack: command not found
Finally after some trying I was able to make it work using this command in git bash node_modules/.bin/webpack ./script-1.js bundle.js
Is there a way to fix this, so I can just type webpack instead of whole path ? Also is there a way to fix path in PowerShell ?
This is mine package.json
{
"name": "webpack-playlist",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/iamshaunjp/webpack-playlist.git"
},
"author": "me",
"license": "MIT",
"bugs": {
"url": "https://github.com/iamshaunjp/webpack-playlist/issues"
},
"homepage": "https://github.com/iamshaunjp/webpack-playlist#readme",
"devDependencies": {
"webpack": "^2.3.3"
}
}
and this is package.json located in node_modules/webpack/package.json
{
"_args": [
[
{
"raw": "webpack",
"scope": null,
"escapedName": "webpack",
"name": "webpack",
"rawSpec": "",
"spec": "latest",
"type": "tag"
},
"C:\\Users\\Djole\\Desktop\\NetNinja\\webpack-playlist"
]
],
"_from": "webpack#latest",
"_id": "webpack#2.3.3",
"_inCache": true,
"_location": "/webpack",
"_nodeVersion": "7.4.0",
"_npmOperationalInternal": {
"host": "packages-12-west.internal.npmjs.com",
"tmp": "tmp/webpack-2.3.3.tgz_1491205859622_0.6350918470416218"
},
"_npmUser": {
"name": "sokra",
"email": "tobias.koppers#googlemail.com"
},
"_npmVersion": "4.0.5",
"_phantomChildren": {},
"_requested": {
"raw": "webpack",
"scope": null,
"escapedName": "webpack",
"name": "webpack",
"rawSpec": "",
"spec": "latest",
"type": "tag"
},
"_requiredBy": [
"#DEV:/",
"#USER"
],
"_resolved": "https://registry.npmjs.org/webpack/-/webpack-2.3.3.tgz",
"_shasum": "eecc083c18fb7bf958ea4f40b57a6640c5a0cc78",
"_shrinkwrap": null,
"_spec": "webpack",
"_where": "C:\\Users\\Djole\\Desktop\\NetNinja\\webpack-playlist",
"author": {
"name": "Tobias Koppers #sokra"
},
"bin": {
"webpack": "./bin/webpack.js"
},
"bugs": {
"url": "https://github.com/webpack/webpack/issues"
},
"dependencies": {
"acorn": "^4.0.4",
"acorn-dynamic-import": "^2.0.0",
"ajv": "^4.7.0",
"ajv-keywords": "^1.1.1",
"async": "^2.1.2",
"enhanced-resolve": "^3.0.0",
"interpret": "^1.0.0",
"json-loader": "^0.5.4",
"loader-runner": "^2.3.0",
"loader-utils": "^0.2.16",
"memory-fs": "~0.4.1",
"mkdirp": "~0.5.0",
"node-libs-browser": "^2.0.0",
"source-map": "^0.5.3",
"supports-color": "^3.1.0",
"tapable": "~0.2.5",
"uglify-js": "^2.8.5",
"watchpack": "^1.3.1",
"webpack-sources": "^0.2.3",
"yargs": "^6.0.0"
},
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
"devDependencies": {
"beautify-lint": "^1.0.3",
"benchmark": "^2.1.1",
"bundle-loader": "~0.5.0",
"codacy-coverage": "^2.0.1",
"codecov.io": "^0.1.2",
"coffee-loader": "~0.7.1",
"coffee-script": "^1.10.0",
"coveralls": "^2.11.2",
"css-loader": "~0.25.0",
"es6-promise-polyfill": "^1.1.1",
"eslint": "3.12.2",
"eslint-plugin-node": "^3.0.5",
"express": "~4.13.1",
"extract-text-webpack-plugin": "^2.0.0-beta",
"file-loader": "~0.9.0",
"i18n-webpack-plugin": "^0.3.0",
"istanbul": "^0.4.5",
"jade": "^1.11.0",
"jade-loader": "~0.8.0",
"js-beautify": "^1.5.10",
"less": "^2.5.1",
"less-loader": "^2.0.0",
"lodash": "^4.17.4",
"mocha": "^3.2.0",
"mocha-lcov-reporter": "^1.0.0",
"nsp": "^2.6.1",
"raw-loader": "~0.5.0",
"react": "^15.2.1",
"react-dom": "^15.2.1",
"script-loader": "~0.7.0",
"should": "^11.1.1",
"simple-git": "^1.65.0",
"sinon": "^1.17.7",
"style-loader": "~0.13.0",
"url-loader": "~0.5.0",
"val-loader": "~0.5.0",
"vm-browserify": "~0.0.0",
"webpack-dev-middleware": "^1.9.0",
"worker-loader": "~0.7.0"
},
"directories": {},
"dist": {
"shasum": "eecc083c18fb7bf958ea4f40b57a6640c5a0cc78",
"tarball": "https://registry.npmjs.org/webpack/-/webpack-2.3.3.tgz"
},
"engines": {
"node": ">=4.3.0 <5.0.0 || >=5.10"
},
"files": [
"lib/",
"bin/",
"buildin/",
"hot/",
"web_modules/",
"schemas/"
],
"gitHead": "ba24c1b163dc038ed738eb4a57dcb241bf63146d",
"homepage": "https://github.com/webpack/webpack",
"license": "MIT",
"main": "lib/webpack.js",
"maintainers": [
{
"name": "jhnns",
"email": "mail#johannesewald.de"
},
{
"name": "sokra",
"email": "tobias.koppers#googlemail.com"
},
{
"name": "thelarkinn",
"email": "sean.larkin#cuw.edu"
}
],
"name": "webpack",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/webpack/webpack.git"
},
"scripts": {
"appveyor:benchmark": "npm run benchmark",
"appveyor:test": "node --max_old_space_size=4096 node_modules\\mocha\\bin\\mocha --harmony test/*.test.js",
"beautify-lint": "beautify-lint 'lib/**/*.js' 'hot/**/*.js' 'bin/**/*.js' 'benchmark/*.js' 'test/*.js'",
"benchmark": "mocha test/*.benchmark.js --harmony -R spec",
"build:examples": "cd examples && node buildAll.js",
"cover": "node --harmony ./node_modules/istanbul/lib/cli.js cover -x '**/*.runtime.js' node_modules/mocha/bin/_mocha -- test/*.test.js",
"cover:min": "node --harmony ./node_modules/.bin/istanbul cover -x '**/*.runtime.js' --report lcovonly node_modules/mocha/bin/_mocha -- test/*.test.js",
"lint": "eslint lib bin hot buildin test/**/webpack.config.js test/binCases/**/test.js examples/**/webpack.config.js",
"lint-files": "npm run lint && npm run beautify-lint",
"nsp": "nsp check --output summary",
"pretest": "npm run lint-files",
"publish-patch": "npm run lint && npm run beautify-lint && mocha && npm version patch && git push && git push --tags && npm publish",
"test": "mocha test/*.test.js --harmony --check-leaks",
"travis:benchmark": "npm run benchmark",
"travis:lint": "npm run lint-files && npm run nsp",
"travis:test": "npm run cover:min"
},
"version": "2.3.3",
"web": "lib/webpack.web.js"
}
EDIT:
I've come with following solution in the end:
Add this to your package.json file
"scripts" : {
"build" : "webpack ./entry.js bundle.js"
}
and then type npm run build this will still run the local version because npm will first look in ./node_modules/.bin/

That kind of path is what is used in a git for Windows bash.
See this issue
We use cmdr (http://cmder.net/ ) to emulate console on Windows machines.
Still we had to modify scripts and separate build to clean and build tasks to get it working.
"scripts": {
"clean": "rm -rf dist",
"build": "node_modules/.bin/babel-node -- ./node_modules/webpack/bin/webpack.js --stats --config ./webpack/prod.config.js",
...
},
You can see a similar instruction in this project package.json:
"build-main": "cross-env NODE_ENV=production node -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.electron.js --progress --profile --colors",

Related

React import problem, 'Module not found: Can't resolve' while import package wechaty

I'm new to nodejs and react. In my project, I use a package "wechaty". And it works fine when my project is a pure nodejs.
Then when I try to integrate "wechaty" with react, it failed to compile and report errors.
// Code in App.js
import { WechatyBuilder, ScanStatus, log} from "wechaty"
When I run npm start/yarn start, the error message appears
Failed to compile.
./src/App.js Module not found: Can't resolve 'wechaty' in
'D:\git\chat-client\src'
I guess it may be because there is no 'module' field in the package.json of 'wechaty', so I add that field.
"module": "./dist/esm/src/mods/mod.js",
The exact problem do disappeared. But it still cannot resolve sub modules.
Failed to compile.
./node_modules/wechaty/dist/esm/src/mods/mod.js Module not found:
Can't resolve 'wechaty-puppet/helpers' in
'D:\git\chat-client\node_modules\wechaty\dist\esm\src\mods'
Compiling... Failed to compile.
Even worse is that 'wechaty' has many dependence packages, and all the dependence packages have the same problem.
Here follows the package.json of 'wechaty':
{
"name": "wechaty",
"version": "1.0.6",
"description": "Wechaty is a RPA SDK for Chatbot Makers.",
"type": "module",
"exports": {
".": {
"import": "./dist/esm/src/mods/mod.js",
"require": "./dist/cjs/src/mods/mod.js"
},
"./impls": {
"import": "./dist/esm/src/mods/impls.js",
"require": "./dist/cjs/src/mods/impls.js"
},
"./users": {
"import": "./dist/esm/src/mods/users.js",
"require": "./dist/cjs/src/mods/uses.js"
}
},
"typesVersions": {
"*": {
"users": [
"./dist/esm/src/mods/users.d.ts"
],
"impls": [
"./dist/esm/src/mods/impls.d.ts"
]
}
},
"types": "./dist/esm/src/mods/mod.d.ts",
"engines": {
"node": ">=16",
"npm": ">=7"
},
"wechaty": {
"DEFAULT_PORT": 8080,
"DEFAULT_PROTOCOL": "io|0.0.1",
"DEFAULT_APIHOST": "api.chatie.io"
},
"scripts": {
"build": "tsc && tsc -p tsconfig.cjs.json",
"changelog": "docker run -it --rm -e CHANGELOG_GITHUB_TOKEN -v \"$(pwd)\":/usr/local/src/your-app ferrarimarco/github-changelog-generator -u wechaty -p wechaty && sed -i'.bak' /greenkeeper/d CHANGELOG.md && sed -i'.bak' /Snyk/d CHANGELOG.md && sed -i'.bak' '/An in-range update of/d' CHANGELOG.md && node --no-warnings --loader=ts-node/esm scripts/sort-contributiveness.ts < CHANGELOG.md > CHANGELOG.new.md 2>/dev/null && cat CHANGELOG.md >> CHANGELOG.new.md && mv CHANGELOG.new.md CHANGELOG.md",
"check-node-version": "check-node-version --node \">= 16\"",
"clean": "shx rm -fr dist/*",
"coverage": "nyc report --reporter=lcov",
"demo": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/ding-dong-bot.ts",
"dist": "npm-run-all clean build dist:commonjs",
"dist:commonjs": "jq -n \"{ type: \\\"commonjs\\\" }\" > dist/cjs/package.json",
"docs": "bash -x scripts/generate-docs.sh",
"doctor": "npm run check-node-version && node --no-warnings --loader=ts-node/esm bin/doctor.ts",
"io-client": "node --no-warnings --loader=ts-node/esm bin/io-client.ts",
"lint:es": "eslint --ignore-pattern node_modules/ --ignore-pattern fixtures/ \"{bin,examples,src,scripts,tests}/**/*.ts\"",
"lint:md": "markdownlint README.md",
"lint:sh": "bash -n bin/*.sh",
"lint:ts": "tsc --isolatedModules --noEmit",
"lint": "npm-run-all check-node-version lint:es lint:ts lint:sh lint:md",
"puppet-install": "node --no-warnings --loader=ts-node/esm bin/puppet-install.ts",
"sloc": "sloc bin examples scripts src tests --details --format cli-table --keys total,source,comment && sloc bin examples scripts src tests",
"start": "npm run demo",
"test:pack": "bash -x scripts/npm-pack-testing.sh",
"test:shell": "shellcheck bin/*.sh scripts/*.sh",
"test:unit": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" TAP_TIMEOUT=60 tap \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\"",
"test": "npm run lint && nyc npm run test:unit && npm run sloc",
"typedoc": "bash scripts/typedoc.sh"
},
"repository": {
"type": "git",
"url": "git+https://github.com/wechaty/wechaty.git"
},
"bin": {
"wechaty-doctor": "dist/esm/bin/doctor.js",
"wechaty-io-client": "dist/esm/bin/io-client.js",
"wechaty-puppet-install": "dist/esm/bin/puppet-install.js",
"wechaty-version": "dist/esm/bin/version.js"
},
"keywords": [
"ai",
"bot",
"chatbot",
"chatie",
"conversational",
"framework",
"robot",
"rpa",
"sdk",
"wechat",
"wecom",
"wxwork",
"lark",
"TikTok",
"weixin",
"whatsapp",
"微信"
],
"author": {
"name": "Huan LI (李卓桓)",
"email": "zixia#zixia.net",
"url": "https://linkedin.com/in/zixia/"
},
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/wechaty/wechaty/issues"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/wechaty"
},
"homepage": "https://github.com/wechaty/",
"dependencies": {
"clone-class": "^1.0.2",
"cockatiel": "^2.0.2",
"dotenv": "^10.0.0",
"json-rpc-peer": "^0.17.0",
"open-graph": "^0.2.6",
"state-switch": "^1.1.15",
"uuid": "^8.3.2",
"wechaty-puppet": "^1.0.1",
"wechaty-puppet-service": "^1.0.1",
"ws": "^8.2.3"
},
"devDependencies": {
"#chatie/eslint-config": "^1.0.3",
"#chatie/git-scripts": "^0.6.2",
"#chatie/semver": "^0.4.7",
"#chatie/tsconfig": "^1.0.2",
"#types/dotenv": "^8.2.0",
"#types/glob": "^7.2.0",
"#types/open-graph": "^0.2.2",
"#types/raven": "^2.5.4",
"#types/uuid": "^8.3.1",
"#types/ws": "^8.2.0",
"check-node-version": "^4.1.0",
"coveralls": "^3.1.1",
"glob": "^7.2.0",
"jsdoc-to-markdown": "^7.1.0",
"nyc": "^15.1.0",
"qrcode-terminal": "^0.12.0",
"raven": "^2.6.4",
"sloc": "^0.2.1",
"typed-emitter": "^1.4.0",
"typedoc": "^1.0.0-dev.4 ",
"wechaty-puppet-mock": "^1.0.1",
"wechaty-puppet-padlocal": "^0.4.2"
},
"files": [
"bin/",
"dist/",
"src/"
],
"publishConfig": {
"access": "public",
"tag": "latest"
},
"collective": {
"type": "opencollective",
"url": "https://opencollective.com/wechaty"
},
"git": {
"scripts": {
"pre-push": "npx git-scripts-pre-push"
}
}
}
Here follows the ./dist/esm/src/mods/mod.js
export { WechatyBuilder, } from '../wechaty-builder.js';
export * as type from 'wechaty-puppet/types';
export * as payload from 'wechaty-puppet/payloads';
export * as helper from 'wechaty-puppet/helpers';
export * as impl from './impls.js';
export * as user from './users.js';
export * from './users.js';
export { ScanStatus, } from 'wechaty-puppet/types';
export { log, config, qrcodeValueToImageUrl, VERSION, } from '../config.js';
export { IoClient, } from '../io-client.js';
//# sourceMappingURL=mod.js.map
Here follows package.js of my own project:
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"socket.io-client": "^4.4.0",
"web-vitals": "^1.0.1",
"wechaty": "^1.0.6"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

Deploying React app with npm run build not finding files

I currently have a directory myproject/
In myproject I have these
/src
/public
package.json
etc.
Normal stuff you'd see in a react app.
I pushed this to a server aws lightsail nodejs
I then run npm install.
After I do all this I go and run npm run build
I get this output:
> react-scripts build
Creating an optimized production build...
Failed to compile.
./src/index.js
Cannot find module: 'layouts/Admin.jsx'. Make sure this package is installed.
You can install this package by running: npm install layouts/Admin.jsx.
The files it's calling for are in the directory.
Here is package.json
{
"name": "argon-dashboard-react",
"version": "1.0.0",
"description": "React version of Argon Dashboard by Creative Tim",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/creativetimofficial/argon-dashboard-react.git"
},
"keywords": [
"react",
"reactjs",
"argon",
"argon-react",
"dashboard",
"dashboard-react",
"argon-dashboard",
"argon-dashboard-react"
],
"author": "Creative Tim",
"license": "MIT",
"bugs": {
"url": "https://github.com/creativetimofficial/argon-dashboard-react/issues"
},
"homepage": "https://demos.creative-tim.com/argon-dashboard-react/",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install && npm start",
"compile-sass": "node-sass src/assets/scss/argon-dashboard-react.scss src/assets/css/argon-dashboard-react.css",
"minify-sass": "node-sass src/assets/scss/argon-dashboard-react.scss src/assets/css/argon-dashboard-react.min.css --output-style compressed",
"map-sass": "node-sass src/assets/scss/argon-dashboard-react.scss src/assets/css/argon-dashboard-react.css --source-map true"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"dependencies": {
"#material-ui/core": "^4.6.1",
"#material-ui/icons": "^4.5.1",
"chart.js": "2.7.3",
"classnames": "2.2.6",
"firebase": "^6.6.2",
"firebase-admin": "^8.8.0",
"http2": "^3.3.7",
"moment": "2.24.0",
"node-sass": "4.11.0",
"nouislider": "13.1.1",
"react": "16.9.0",
"react-bootstrap-table-next": "^3.2.1",
"react-chartjs-2": "2.7.4",
"react-copy-to-clipboard": "5.0.1",
"react-data-table-component": "4.0.1",
"react-datepicker": "^2.9.6",
"react-datetime": "2.16.3",
"react-dom": "16.9.0",
"react-google-maps": "9.4.5",
"react-loading-screen": "0.0.17",
"react-router-dom": "4.3.1",
"react-scripts": "2.1.8",
"reactstrap": "7.1.0",
"recompose": "^0.30.0",
"styled-components": "^4.4.1",
"sweetalert2": "^9.5.4",
"sweetalert2-react-content": "^2.0.2"
},
"devDependencies": {
"#types/googlemaps": "3.30.18",
"#types/markerclustererplus": "2.1.33",
"#types/react": "16.8.7",
"typescript": "3.3.3333"
}
}
Any idea what's going on with this?
The problem was related to the way I was using my import paths for components.
In example, currently I have:
import UserHeader from "components/Headers/UserHeader.jsx";
The correct way to have set them was:
import UserHeader from "../../components/Headers/UserHeader.jsx";
What was throwing me off was that locally it worked.

How do I change the entry point in a package.json?

everyone.
I'm new to node.js and front development and I'm working with this template:
https://github.com/coreui/coreui-free-bootstrap-admin-template
and I have a silly question that no one seems to address in the forums in a straightforward, simple way.
The template's entry point is the index.html. I tried to change it in the package.json to the login.html, because I want the app to open that page first, of course, but I cannot make it work. I know... It's so silly. I'm sure it's very easy to solve but all the examples I find explain the set up using webpack, and this template doesn't use it.
Could anyone give me a hint? I'll deeply appreciate it.
I copy the package.json for you:
{
"name": "#coreui/coreui-free-bootstrap-admin-template",
"version": "2.1.15",
"description": "Free Bootstrap Admin Template",
"keywords": [
"admin",
"admin panel",
"admin template",
"bootstrap",
"css",
"dashboard",
"framework",
"front-end",
"responsive",
"sass",
"ui kit",
"webapp"
],
"homepage": "https://coreui.io",
"bugs": {
"url": "https://github.com/coreui/coreui-free-bootstrap-admin-template/issues",
"email": "support#coreui.io"
},
"license": "MIT",
"author": {
"name": "Łukasz Holeczek",
"url": "http://holeczek.pl",
"github": "https://github.com/mrholek",
"twitter": "https://twitter.com/lukaszholeczek"
},
"contributors": [
{
"name": "Andrzej Kopański",
"url": "https://github.com/xidedix"
}
],
"main": "src/index.html",
"repository": {
"type": "git",
"url": "git+https://github.com/coreui/coreui-free-bootstrap-admin-template.git"
},
"scripts": {
"build": "npm-run-all build-clean build-copy build-vendors",
"build-clean": "rimraf dist",
"build-copy": "copyfiles -a -e \"src/scss/**/*\" -u 1 \"src/**/*\" dist/",
"build-vendors": "node build/vendors.js",
"css": "npm-run-all --parallel css-compile* --sequential css-prefix css-minify*",
"css-compile": "node-sass --output-style expanded --source-map true --source-map-contents true --precision 6 src/scss/style.scss src/css/style.css",
"css-compile-vendors": "node build/vendors-sass.js",
"css-lint": "stylelint --config build/.stylelintrc --syntax scss \"src/scss/**/*.scss\"",
"css-minify": "cleancss --level 1 --source-map --source-map-inline-sources --output src/css/style.min.css src/css/style.css",
"css-prefix": "postcss --config build/postcss.config.js --replace \"src/css/*.css\" \"!src/css/*.min.css\"",
"js": "npm-run-all --parallel js-compile* js-lint*",
"js-compile": "cross-env PLUGINS=true babel src/js/src/ --out-dir src/js/ --source-maps",
"js-lint": "eslint src/js/src",
"localhost": "browser-sync start --server \"./src\" --serveStatic \"./\" --files \"!./src/js/src/**/*, ./src/**/*, !./src/scss/**/*\"",
"localhost-dist": "browser-sync start --server \"./dist\"",
"pug": "node build/pug.js",
"release-version": "node build/change-version.js",
"serve": "npm-run-all --parallel localhost watch-css watch-js",
"watch-css": "nodemon --ignore dist/ -e scss -x \"npm run css\"",
"watch-js": "nodemon --watch src/js/src/ -x \"npm run js\"",
"watch-pug": "nodemon -e pug -x \"npm run pug\""
},
"dependencies": {
"#coreui/coreui": "^2.1.12",
"#coreui/coreui-plugin-chartjs-custom-tooltips": "^1.3.1",
"#coreui/icons": "0.3.0",
"bootstrap": "^4.3.1",
"chart.js": "^2.8.0",
"core-js": "^3.1.4",
"flag-icon-css": "^3.3.0",
"font-awesome": "~4.7.0",
"jquery": "^3.4.1",
"pace-progress": "1.0.2",
"perfect-scrollbar": "^1.4.0",
"popper.js": "^1.15.0",
"regenerator-runtime": "^0.13.2",
"simple-line-icons": "2.4.1"
},
"devDependencies": {
"#babel/cli": "^7.5.0",
"#babel/core": "^7.5.4",
"#babel/plugin-proposal-object-rest-spread": "^7.5.4",
"#babel/plugin-proposal-throw-expressions": "^7.2.0",
"#babel/preset-env": "^7.5.4",
"autoprefixer": "^9.6.1",
"babel-eslint": "^10.0.2",
"babel-plugin-transform-es2015-modules-strip": "^0.1.1",
"browser-sync": "^2.26.7",
"chalk": "^2.4.2",
"clean-css-cli": "^4.3.0",
"copyfiles": "^2.1.1",
"cross-env": "^5.2.0",
"eslint": "^5.16.0",
"eslint-plugin-compat": "^3.2.0",
"foreach-cli": "^1.8.1",
"js-beautify": "^1.10.0",
"node-sass": "^4.12.0",
"nodemon": "^1.19.1",
"npm-run-all": "^4.1.5",
"postcss-cli": "^6.1.3",
"pug": "^2.0.4",
"rimraf": "^2.6.3",
"shelljs": "^0.8.3",
"stylelint": "^10.1.0",
"stylelint-config-recommended-scss": "^3.3.0",
"stylelint-config-standard": "^18.3.0",
"stylelint-order": "^3.0.1",
"stylelint-scss": "^3.9.1"
},
"engines": {
"node": ">=8"
},
"browserslist": [
"last 1 major version",
">= 1%",
"Chrome >= 45",
"Firefox >= 38",
"Edge >= 12",
"Explorer >= 10",
"iOS >= 9",
"Safari >= 9",
"Android >= 4.4",
"Opera >= 30"
]
}

Babel and Deploy Nodejs to Google App Engine

I'm a newbie nodejs. I have a trouble about deploying nodejs app to google app engine. This is my error, I have been trying to fix it but it's not work. I've installed babel.
Bug
Updating service [default]...failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
restaurant_api#1.0.0 prestart /app
npm run -s build
You have mistakenly installed the babel package, which is a no-op in Babel 6.
Babel's CLI commands have been moved from the babel package to the babel-cli package.
npm uninstall babel
npm install --save-dev babel-cli
This is my package.json
"main": "dist",
"scripts": {
"dev": "NODE_ENV=development nodemon -w src --exec \"babel-node src --presets es2015,stage-0\"",
"build": "babel src -s -D -d dist --presets es2015,stage-0",
"start": "NODE_ENV=production pm2 start dist",
"prestart": "npm run -s build",
"lint": "eslint src",
"test": "echo \"Error: no test specified\" && exit 1",
"babel-version": "babel --version"
},
"eslintConfig": {
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
},
"env": {
"node": true
},
"rules": {
"no-console": 0,
"no-unused-vars": 1
}
},
"author": "",
"license": "ISC",
"dependencies": {
"babel": "^6.23.0",
"body-parser": "^1.17.0",
"express": "^4.15.0",
"express-jwt": "^5.1.0",
"jsonwebtoken": "^7.3.0",
"mongoose": "^4.8.5",
"passport": "^0.3.2",
"passport-local": "^1.0.0",
"passport-local-mongoose": "^4.0.0",
"pm2": "^2.4.2"
},
"devDependencies": {
"babel-cli": "^6.23.0",
"babel-eslint": "^7.1.1",
"babel-preset-es2015": "^6.22.0",
"babel-preset-stage-0": "^6.22.0",
"eslint": "^3.16.1"
}
Problem is quite simple, if you notice clearly GAE, does not install dev-dependencies. So move your dev-deps above inside deps , like I did and babel no found error is gone.
{
"name": "scraping",
"version": "0.3.0",
"description": "Starter project for an ES6 RESTful Express API",
"main": "dist",
"scripts": {
"dev": "nodemon -w src --exec \"babel-node src --presets es2015,stage-0\"",
"build": "babel src -s -D -d dist --presets es2015,stage-0",
"start": "node dist",
"prestart": "npm run -s build",
"test": "eslint src"
},
"eslintConfig": {
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
},
"env": {
"node": true
},
"rules": {
"no-console": 0,
"no-unused-vars": 1
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/developit/express-es6-rest-api.git"
},
"author": "Saransh Sharma <jason#developit.ca>",
"license": "MIT",
"dependencies": {
"body-parser": "^1.13.3",
"compression": "^1.5.2",
"cors": "^2.7.1",
"express": "^4.13.3",
"morgan": "^1.8.0",
"resource-router-middleware": "^0.6.0",
"#jonstuebe/scraper": "^0.1.4",
"babel-cli": "^6.9.0",
"babel-core": "^6.9.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-0": "^6.5.0",
"eslint": "^3.1.1",
"nodemon": "^1.9.2"
},
"devDependencies": {
"babel-cli": "^6.9.0",
"babel-core": "^6.9.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-0": "^6.5.0",
"eslint": "^3.1.1",
"nodemon": "^1.9.2"
},
"bugs": {
"url": "https://github.com/developit/express-es6-rest-api/issues"
},
"homepage": "https://github.com/developit/express-es6-rest-api#readme",
"keywords": [
"scraper",
"product",
"from",
"amazon"
]
}
The clue is in the error message.
In your devDependencies section, you already have babel-cli included.
However, your dependencies section still has a reference to "babel": "^6.23.0".
Either remove this line, or replace it with babel-cli, leaving you with:
"dependencies": {
"babel-cli": "^6.23.0",
"body-parser": "^1.17.0",
"express": "^4.15.0",
"express-jwt": "^5.1.0",
"jsonwebtoken": "^7.3.0",
"mongoose": "^4.8.5",
"passport": "^0.3.2",
"passport-local": "^1.0.0",
"passport-local-mongoose": "^4.0.0",
"pm2": "^2.4.2"
},
You need to install babel-cli globally, i.e. run the command "npm install babel-cli -g" as part of your build npm script, or create a pre-install script that install it if you want to keep it more organized in case you need to add more things later on.
"scripts": {
"dev": "NODE_ENV=development nodemon -w src --exec \"babel-node src --presets es2015,stage-0\"",
"build": "npm install bable-cli -g && babel src -s -D -d dist --presets es2015,stage-0",

babel-node not recognized while running heroku local web

I tried deploying Node.js API on Heroku, but shows Application Error.
So, used the "heroku local web" command to test any error..and got an error saying that 'babel-node' is not recognized as an internal or external command, operable program or batch file.
On the other hand, when I run the command 'npm start' I dont get any error and the server starts running.
package.json
{
"name": "apollo-starter-kit",
"version": "0.1.0",
"description": "Minimal set of code to write a GraphQL server with Apollo graphql-tools",
"scripts": {
"start": "nodemon ./server.js --exec babel-node",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint ."
},
"repository": {
"type": "git",
"url": "git+https://github.com/apollostack/apollo-starter-kit.git"
},
"keywords": [
"Node.js",
"Javascript",
"GraphQL",
"Express",
"Apollo",
"Meteor"
],
"author": "Jonas Helfer <jonas#helfer.email>",
"license": "MIT",
"bugs": {
"url": "https://github.com/apollostack/apollo-starter-kit/issues"
},
"homepage": "https://github.com/apollostack/apollo-starter-kit#readme",
"dependencies": {
"apollo-server": "^0.1.2",
"casual": "^1.5.10",
"cors": "^2.8.1",
"express": "^4.13.4",
"lodash": "^4.17.4",
"mongoose": "^4.8.1",
"sequelize": "^3.30.2",
"sqlite": "^2.3.0"
},
"devDependencies": {
"babel-cli": "6.5.1",
"babel-core": "^6.5.2",
"babel-eslint": "^6.0.0-beta.6",
"babel-loader": "6.2.3",
"babel-plugin-inline-import": "^2.0.1",
"babel-polyfill": "6.5.0",
"babel-preset-es2015": "6.5.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "6.5.0",
"casual": "^1.5.10",
"eslint": "^2.4.0",
"eslint-config-airbnb": "^6.1.0",
"eslint-plugin-import": "^1.1.0",
"eslint-plugin-react": "^4.2.3",
"graphql": "^0.6.0",
"nodemon": "^1.9.1"
},
"peerDependencies": {
"graphql": "^0.5.0 || ^0.6.0"
},
"eslintConfig": {
"parser": "babel-eslint",
"extends": [
"airbnb/base",
"plugin:import/errors"
],
"rules": {
"no-use-before-define": 0,
"arrow-body-style": 0,
"dot-notation": 0,
"no-console": 0
},
"env": {
"mocha": true
}
}
}
I think the most likely cause is that babel is part of dev dependencies and those are not installed by default via official node.js buildpack. Change NPM_CONFIG_PRODUCTION to false and it should work.
You can use command line
heroku config:set NPM_CONFIG_PRODUCTION=false
You can always login into Heroku dyno to check if everything is installed properly
heroku run bash
You should not be using babel-node in production. It is unnecessarily heavy, with high memory usage due to the cache being stored in memory. You will also always experience a startup performance penalty as the entire app needs to be compiled on the fly.
ref: https://medium.com/#Cuadraman/how-to-use-babel-for-production-5b95e7323c2f

Resources