I tried to use npm-watch as file watcher to compile scss files. As I run npm run watch, the script runs and does what I expected. But after the run, it immediately ends and does not run again on file change. In other words, it works but it does not watching. It only runs once. What could be the problem?
This is package.json
{
"name": "limitless",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"autoprefixer": "^10.2.5"
},
"devDependencies": {
"jshint": "^2.10.3",
"node": "14.16.0",
"node-sass": "^5.0.0",
"npm-watch": "^0.11.0",
"uglify-js": "^3.16.1",
"uglifycss": "^0.0.29"
},
"watch": {
"patterns": ["www/scss"],
"extensions": ["scss"],
"delay": "2000"
},
"scripts": {
"watch": "node-sass www/scss/theme.scss www/css/theme.css"
}
}
The problem was that called npm run watch insted of npm-watch.
The solution looks like this:
"watch": {
"compile-css": {
"patterns": ["www/scss"],
"extensions": ["scss"],
"delay": 250,
"runOnChangeOnly": true
},
"compile-js": {
"patterns": ["www/js/src"],
"extensions": ["js"],
"delay": 250,
"runOnChangeOnly": true
}
},
"scripts": {
"compile-css": "npm run scss && npm run minify-css",
"compile-js": "uglifyjs www/js/src/app.js -o www/js/dist/app.min.js & uglifyjs www/js/src/main.js -o www/js/dist/main.min.js",
"scss": "node-sass www/scss/theme.scss www/css/theme.css",
"minify-css": "css-minify -f www/css/theme.css -o www/css",
"js": "npm run uglifyjs ",
"watch": "npm-watch"
},
and so I run npm run watch which calls npm-watch which triggers other scripts if files has been changed.
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"
]
}
}
I'm trying to get test results and code coverage data after running jest tests. The resulting file contains the results of the tests, but no coverage data. I'm using jest-junit as my reporter. Here's what's in my package.json:
"scripts": {
"test": "jest --verbose --silent --coverage --coverageDirectory=./",
"start": "node server.js",
"dev": "nodemon server.js"
},
"jest": {
"testEnvironment": "node",
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"coverageReporters": [
"text",
"jest-junit"
],
"reporters": [
"default",
"jest-junit"
]
},
"jest-junit": {
"suiteName": "jest tests",
"outputDirectory": ".",
"outputName": "junit.xml",
"uniqueOutputName": "false",
"classNameTemplate": "{classname}-{title}",
"titleTemplate": "{classname}-{title}",
"ancestorSeparator": " › ",
"usePathForSuiteName": "true"
}
I have a node js gradle application. I am not sure how to run the application locally.
I have done gradle build (./gradlew) and npm run build(compile). All my dependencies are in the node_modules.
I have a server.ts file having server code apart from the routing.
My package.json-
{
"name": "app",
"version": "..",
"description": "",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"prepublish": "npm run build",
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"async-child-process": "^1.1.1",
..
},
"devDependencies": {
"#types/handlebars": "^4.0.36",
"#types/node": "^8.10.45",
"#types/pg-types": "^1.11.4"
}
}
How to run the project on the server.
tsconfig.json
{
"compilerOptions": {
"outDir": "./build/js/",
"sourceMap": false,
"noImplicitAny": false,
"module": "commonjs",
"declaration":true,
"target": "es2015"
},
"include": [
"src/main/ts/**/*.ts"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
Node.js will not run ts code. after build it'll js code in dist directory(depends on tsconf.json).
In package.json add below code, run npm run serve to start server.
or go to dist dir and run node server.js.
I have created a sample on GitHub check here
"scripts": {
"serve": "npm run build && npm run start",
"start": "node dist/server.js",
"build": "tsc"
}
I was following tutorial that I have found here. Previously the command was running fine, but after some changes when I runnpm run nodemon it gives me error
Here is my package.json
{
"name": "smashing-react-i18n",
"version": "1.0.0",
"description": "",
"main": "dist/bundle.js",
"betterScripts": {
"build": {
"command": "webpack -p",
"env": {
"NODE_ENV": "production"
}
},
"nodemon": {
"command": "nodemon server.js",
"env": {
"NODE_PATH": "src"
}
}
},