I'm trying the get the Visual Studio Code debugger working in my angular/typescript application but it's not working.
Here's what I have:
.vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug node",
"port": 9229,
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"localRoot": "${workspaceFolder}\\.dist",
"remoteRoot": "/usr/src/api/.dist",
"type": "node"
}
]
}
scripts/local-entry-point.sh
#!/usr/bin/env sh
set -e
echo "STARTING local-entry-point.sh"
FOLDER=/tmp/.dist
if [ ! -d "$FOLDER" ]; then
mkdir /tmp/.dist
fi
false | cp -ir ${FOLDER} /usr/src/api/ 2>/dev/null
rm -rf ${FOLDER}
cd scripts
npm run watch
scripts/package.json
{
"private": true,
"devDependencies": {
"#effect-ts/core": "^0.11.1"
},
"scripts": {
"watch": "nodemon --watch '/usr/src/api/.dist/**/*' -e ts,json,js -x npm run debug",
"debug": "node --inspect=0.0.0.0:9229 /usr/src/api/.dist/start.js"
}
}
docker-compose.yml
...
ports:
- 4002:8800
- 9229:9229
...
I put breakpoints in both my Typescript and the compiled Javascript in the .dist folder (on the corresponding line):
I start my application (npm run docker), start the debugger in vscode, go through the steps to run the code, but the breakpoints don't get hit.
Seems like you are using Typescript. AFAIK VSCode debugger needs a sourcemap to put breakpoints on ts projects. I think this doc might help https://code.visualstudio.com/docs/typescript/typescript-debugging
Related
i'm having a hard time to understand how to run all of my .js files using package.js files
i have almost 2000.js scripts i need to run them one by one, i'm using a api made by gameflip
in the folder i found package.js, but i don't know how to use it ,
can anyone tell me how to do that ? thank you
here the script :
{
"name": "gfapi",
"version": "0.1.1",
"description": "Gameflip API",
"keywords": "Gameflip",
"homepage": "https://github.com/iJJi/gfapi",
"bugs": "https://github.com/iJJi/gfapi/issues",
"author": {
"name": "Eng-Shien Wu",
"email": "engshien.wu#ijji.com"
},
"license": "MIT",
"private": true,
"files": [
"index.js"
],
"repository": "iJJi/gfapi",
"engines": {
"node": ">=8.5.0"
},
"scripts": {
"bulk_listing": "node src/samples/bulk_listing.js",
"test": "ENVIRONMENT=mocha mocha src/test --recursive",
"docs": "jsdoc -c jsdoc_conf.js -d docs -P package.json index.js; docco -o docs/samples src/samples/*.js src/samples/*.rb"
},
"dependencies": {
"base-64": "^0.1.0",
"bluebird": "^3.5.0",
"bunyan": "^1.8.12",
"file-type": "^8.1.0",
"http-errors": "^1.6.2",
"node-rest-client-promise": "^3.1.1",
"promise-ratelimit": "^0.0.3",
"request": "^2.85.0",
"request-promise": "^4.2.2",
"speakeasy": "^2.0.0"
},
"devDependencies": {
"marked": "^0.3.19",
"docco": "^0.7.0",``
"jsdoc": "^3.5.5"
}
}
What you posted isn't a package.js (I don't even know if it exists), but a package.json. It's generated by NPM, the Node Package Manager. It's a list of all the project's dependencies. I think that what you're looking for are the npm scripts, they are in the script object of package.json.
npm run <script>
# For example :
npm run bulk_listing
npm run test
npm run docs
Each script will run its associated command in this package.json.
npm run bulk_listing
# Will do the same thing as:
node src/samples/bulk_listing.js
More about package.json.
The script I talked about below
If you want to run all the scripts, this should do the job :
const fileNames = ["path/to/fileA", "fileB"]; // I assume you have something to get all the files path. Isn't that npm run bulk_listing ?
fileNames.forEach(async (path, index) => {
// It's pretty much like 'node <path>'
await require(path);
// All the code here is executed AFTER the script has been launched
console.log(`LAUNCHED ${index} | ${path}`)
});
I'm currently using Browser Sync newest version (2.24.6) installed via npm install -g browser-sync and I did so in my C:\Users\USERNAME\Google Drive I am using Gulp.
I start browser sync by running browser-sync start --server --files '*.html, css/*.css, js/*.js' in bash and my project opens up. The project updates as expected when I change HTML, CSS, and/or JS files.
However, when I edit my package.json file (which is not in the same directory) under "scripts" with "start": browser-sync start --server --files '*.html, css/*.css, js/*.js' and then run npm start in my bash console I get a page but all I see is Cannot GET / and not my project.
Also, if I try to browser-sync start --server --files '*.html, css/*.css, js/*.js' or in any other project I get the same error.
If I do gulp browser-sync this is what I get:
[06:03:14] Working directory changed to ~\Google Drive
[06:03:15] Using gulpfile ~\Google Drive\gulpfile.js
[06:03:15] Starting 'browser-sync'...
[Browsersync] Access URLs:
--------------------------------------
Local: http://localhost:3000
External: http://192.168.1.116:3000
--------------------------------------
UI: http://localhost:3001
UI External: http://192.168.1.116:3001
--------------------------------------
[Browsersync] Serving files from: ./
Here is my gulpfile.js :
const gulp = require("gulp");
const browserSync = require('browser-sync').create();
gulp.task('browser-sync', function () {
browserSync.init({
server: {
baseDir: './',
}
});
});
And here is my package.json file:
{
"name": "eslint-test",
"version": "1.0.0",
"description": "",
"main": "main.js",
"dependencies": {
"browser-sync": "^2.24.6",
"gulp-sass": "^4.0.1"
},
"devDependencies": {
"eslint": "^4.18.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.9.0",
"gulp": "^4.0.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "browser-sync start --server --files '*.html, css/*.css, js/*.js'"
},
"author": "",
"license": "ISC"
}
I apologize if this is not the right place but I have searched and watched videos for about 2 hours with no answers found. I appreciate any and all help/links.
First of all I do not know if the problem I am having is because of webpack or electron-builder or a combination.
To the problem.
When I build for development I am able to use installed node-modules in the main.js file specified in my package.json file{"main" : "app/main.js"}.
However when I have used electron builder to create an installer. When I have installed the app using the installer I get the following error message when starting the app:
My guess is that I get this message because the the needed node-modules can not be found by main.js. So how do I make them available?
I hope there is someone smarter than me our just better at googling :)
Package.js:
{
"main": "app/main.js",
"scripts": {
"hot-server": "node hot-server.js",
"build-bundle": "rimraf app/dist.release && better-npm-run build-bundle",
"start": "better-npm-run start",
"start-hot": "better-npm-run start-hot",
"backend": "node backend-dummy.js",
"dist-win": "npm run build-bundle && rimraf dist && build --win --ia32",
"dist-mac": "npm run build-bundle && rimraf dist && build --mac"
},
"betterScripts": {
"start": {
"command": "electron ./",
"env": {
"NODE_ENV": "production"
}
},
"start-hot": {
"command": "electron ./",
"env": {
"HOT": 1,
"NODE_ENV": "development"
}
},
"build-bundle": {
"command": "webpack --config webpack.config.production.js --progress --profile --colors",
"env": {
"NODE_ENV": "production"
}
}
},
"bin": {
"electron": "./node_modules/.bin/electron"
},
"build": {
"appId": "app",
"files": [
"dist.release/*",
"dist.resources/*",
"main.js",
"thirdparty/*",
"app.html"
],
"extraFiles": [
"lang/*",
{
"from": "build/extra",
"to": "./",
"filter": "**/*"
}
],
"asar": true
}
So I found a solution to my problem. What I did was I looked at this project:
https://github.com/chentsulin/electron-react-boilerplate
Where they have a special webpack.config.electron.js file that bundles all the node_modules for the main.development.js file into a main.js file that contains everything we need. And then when the electron program starts it uses this main.js bundle to run. To make this happen you need to add a build script in your package.json file that executes webpack.config.electron.js.
I think it is easier to understand how to solve it by looking the linked project than for me to explain.
I am wanting to create an npm cli tool, I dug around in bower's code and replicated their basic package.json along with the bin and lib/bin file.
On windows it works perfectly, but on linux I just get : No such file or directory
The npm package is: https://www.npmjs.com/package/quilk
Here is the code, package.json:
{
"name": "quilk",
"version": "0.1.3",
"description": "quilk.",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "John Carmichael",
"keywords": [
"builder", "watcher", "fast", "quilk"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/johnc1984/quilk"
},
"main": "lib",
"bin": {
"quilk": "bin/quilk"
},
"files": [
"bin",
"lib"
],
"homepage": "https://github.com/johnc1984/quilk",
"engines": {
"node": ">=0.10.0"
},
"dependencies": {
"browserify" : "13.1.0",
"concat-files" : "0.1.0",
"chokidar" : "1.6.0",
"fs.extra" : "1.3.2",
"javascript-natural-sort" : "0.7.1",
"jdc-node-cliarg-reader" : "1.0.0",
"less" : "2.7.1",
"node-notifier" : "4.6.1",
"node-minify" : "1.3.9",
"q" : "1.4.1",
"recursive-readdir" : "2.0.0"
}
}
bin/quilk:
#!/usr/bin/env node
require('../lib/bin/quilk');
lib/bin/quilk
process.bin = process.title = 'quilk';
console.log('This is the quilk script.');
The end result of installing this globally on windows is the console.log is run on the output is This is the quilk script. after i simply type quilk.
On Ubuntu 14lts though, trying to run the freshly, globally installed npm module results in the output of : No such file or directory
What am I missing to get this run on linux?
(when i run the command to list the globally installed npm modules npm ls -g quilk is listed)
Further info:
I get the exact same issue on the following builds:
Ubuntu 14lts, node 6.4.0, npm 3.10.3
Debian 6.0.10, node 0.12.7, npm 2.11.3
I found the answer.
It turns out to be some kind of bug in npm on windows 10.
After publishing the same package from a linux box, the npm package now works on both linux and windows leading me to believe that npm publish on windows has some bug in it somewhere.
Issue reported: https://github.com/npm/npm/issues/13808
I'm working with highcharts-browserify. This is what my package.json file looks like:
{
"main": "index.js",
"scripts": {
"watch-index": "watchify index.js -o ../../static/js/index.js --debug --verbose",
"watch": "npm run watch-index",
"build-index": "browserify index.js | uglifyjs > ../../static/js/index.min.js",
"build": "npm run build-index"
},
"dependencies": {
"highcharts-browserify": "^0.1.5-4.1.7",
"jquery": "^1.11.3",
}
}
However, when I run npm run watch, the compiled file has v4.0.4 of Highcharts in it, not the latest version (v4.1.7).
How can I make sure I've got the latest version?
I need to use the latest version because of this bug in x-axis labels in v4.0.4 of Highcharts: http://jsfiddle.net/5z8rf83y/7/
The highcharts-browserify library currently uses v 4.0.4.
https://github.com/soldair/highcharts-browserify/blob/master/highcharts.js#L2
You could open a ticket to have it updated, or fix it and submit a pull request.
Also, you can by pass using this library, and use browserify-shim which would look like this -
{
"browserify": {
"transform": [
"browserify-shim"
]
},
"browserify-shim": {
"Highcharts": {
"depends": ["HighchartsAdapter:HighchartsAdapter"],
"exports": "Highcharts"
},
"HighchartsAdapter": {"exports":"HighchartsAdapter"}
},
"browser": {
"Highcharts": "./bower_components/highcharts-release/highcharts.src.js",
"HighchartsAdapter": "./bower_components/highcharts-release/adapters/standalone-framework.src.js"
}
}