I am trying to use webpack to analyze my bundles, but I am unable to do so. Get the following errors. How can I fix this?
The contents of my JSON are as follows. I am posting the errors that am receiving on git
"scripts": {
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development --disable-host-check",
"start:local": "BACKEND=http://localhost:3000 webpack-dev-server --mode development",
"test": "jest",
"lint": "eslint --cache --ext mjs,jsx,js --format codeframe \".*.js\" src test",
"coverage": "nyc --all jest --collectCoverage",
"codecov": "rm -rf .nyc_output/ && yarn coverage && nyc report --reporter=text-lcov && codecov",
"heroku-postbuild": "yarn build"
},
"
The error is pretty clear: webpack requires that you use unix style new lines, but it found windows style new lines.
This error is when compiling index.jsx, so the json is irrelevant.
Related
I have an index_template.html file which creates a timestamp when built then creates a duplicate index.html file in this timestamp.sh file
#!/bin/bash
timestamp="$(date +%s)"
echo Adding cache busting timestamp $timestamp
sed "s/%%timestamp%%/?ts=${timestamp}/g" ./build/index_template.html > ./build/index.html
Here is the body of my index_template.html file
<body class="">
<div id="app"></div>
<script src="./assets/js/client.bundle.js%%timestamp%%"></script>
<script src="./assets/js/vendor.js"></script>
<!-- <script>
setInterval(function() {
window.location.reload();
}, 300000);
</script> -->
</body>
I have commented out the script to refresh the page every 5 minutes and entered that into a few javascript files in my react app so only 3 specific pages will reload but every page is still reloading so I assume the index.html file is still running this script. I have run the commands to rebuild it in my package.json file but it is still not working. Does anyone know why?
Here are the scripts in my package.json file
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "http-server ./build -c-1",
"watch": "watchify -e ./src/index.js -o ./build/assets/js/client.bundle.js -t [ babelify ] -
t [ envlocalify ]",
"build": "npm run compile && npm run minify && ./timestamp.sh",
"compile": "browserify -e ./src/index.js -o ./build/assets/js/client.bundle.js -t [ babelify
] -t [ envlocalify --envfile .env.prod ]",
"minify": "uglifyjs ./build/assets/js/client.bundle.js -o ./build/assets/js/client.bundle.js
-c -m",
"start": "npm-run-all --parallel watch serve",
"sync": "npm run build && aws s3 sync build/ s3://spark.generaltraffic.co.uk --
profile=genta-s3 --acl public-read --exclude 'node_modules/*|.env'"
},
I have searched all the answers related to this on stackoverflow but none seems to solve my issue. I was following this link to dockerize my nodejs-mysql app:
https://github.com/varunon9/getting-started-docker-mysql-nodejs#launching-nodejs-app-in-a-container
When I come to step-8 and do docker ps the container is not showing. I have checked the logs and it says "Error: Cannot find module 'express'". My run command is:
docker run -t -d \
--publish 7000:7000 \
--link testmysqlservice:db \
--name=test-nodejs-microservice patient-nodejs
Docker Error Log shown here
After step-8 the sql service seems to get stuck or running not sure:
package.json file
{
"name": "paloit",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"arraylist": "^0.1.0",
"avl": "^1.4.4",
"body-parser": "^1.19.0",
"cheerio": "^1.0.0-rc.3",
"ejs": "^3.0.1",
"express": "^4.17.1",
"hashmap": "^2.4.0",
"hashtable": "git+https://github.com/fabrice102/node-hashtable.git",
"jquery": "^3.4.1",
"jsdom": "^15.2.1",
"morgan": "^1.9.1",
"multimap": "^1.1.0",
"mysql": "^2.17.1",
"request": "^2.88.0",
"sort-map": "^1.0.0",
"sorted-map": "^0.1.8",
"yargs": "^15.0.2"
}
}
Docker file for Mysql
Pull the mysql:5.7 image
FROM mysql:5.7
## The maintainer name and email
LABEL gaga maga <gagad#gmail.com>
# database = test and password for root = password
ENV MYSQL_DATABASE=patientdb \
MYSQL_ROOT_PASSWORD=password
# when container will be started, we'll have `test` database created with this schema
COPY ./patientschem_patient.sql /docker-entrypoint-initdb.d/
Dockerfile for Nodejs
# Use Node v8 as the base image.
FROM node:8
# create and set app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . /usr/src/app
EXPOSE 7000
# Run app
CMD ["npm", "start"]
Part of server.js file
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const mysql = require('mysql');
const request = require('request');
const argv = require('yargs').argv;
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }));
app.set('view engine', 'ejs')
app.get('/', function(req, res) {
........
request(url, function(error, response, body, next) {
var illness = JSON.parse(body)
var ill = illness._embedded.illnesses
//var link = _links.self
res.render(....);
});
});
function getConnection(){
return mysql.createConnection(
{
host: 'localhost',
user: 'root',
password: 'password',
database: 'patientschem'
}
)
}
app.post('/displayhospital', (req, res) => {
console.log("trying to get form data");
.......
const queryString = "INSERT INTO patient (e, d, p) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE d = VALUES(dl), p = VALUES(pl)"
});
const server = app.listen(7000, () => {
console.log(`Express running → PORT ${server.address().port}`);
});
I have two ejs files - index and result
Solved:
The problem was in my package.json indeed. I was missing express. Also arraylist was with small 'a' and in my server.js it was require('Arraylist') which created the conflict.
But surprisingly when I was running the app without docker it was running successfully.
Thank u.
Has anyone ever tried using pkg with featherjs before? I'm having trouble getting it to work.
I get the following error when running my executable:
WARNING: No configurations found in configuration directory:/../project/config
WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment.
pkg/prelude/bootstrap.js:1172
throw error;
^
TypeError: root path required
at Function.serveStatic [as static] (/snapshot/../project/node_modules/serve-static/index.js:40:11)
Not sure where to go from here if anyone has any guidance.
"bin": "src/index.js",
"scripts": {
"test": "npm run eslint && npm run mocha",
"dev": "./node_modules/nodemon/bin/nodemon.js src/",
"eslint": "eslint src/. test/. --config .eslintrc.json",
"mocha": "mocha test/ --recursive --exit",
"start": "node src/",
"pkg": "pkg . -t node9-macos-x64 --out-path pkg"
},
"pkg": {
"assets": [
"src/**/*",
"public/**/*",
"config/**/*",
"node_modules/config/**/*.*"
],
"scripts": [
"src/**/*.js",
"config/**/*.json"
]
},
The error is coming from node-config used by #feathersjs/configuration which trying to load config/default.json from the folder of the running application, not the the bundled package. You can either try building with the NODE_CONFIG environment variable set to the content of config/defualt.json or remove app.configure(configuration()) and app.set the configuration options your application needs, for example by requiring config/default.json (which should also work in theh packaged environment):
const config = require('../config/default.json');
Object.keys(config).forEach(key => {
app.set(key, config[key]);
});
As shown in the screen shot below I am not able to run gulp to concat the JavaScript files. Its saying that gulp is not defined.
I have tried the following commands:
npm install -g gulp
npm install gulp
npm install gulp --save-dev
I have also set the environment variables as following:
C:\Users\<user>\AppData\Roaming\npm;C:\Python27;C:\Users\<user>\AppData\Roaming\npm\node_modules;C:\Users\<user>\AppData\Roaming\npm\node_modules\gulp;
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
//script paths
var jsFiles = 'scripts/*.js',
jsDest = 'dist/scripts';
gulp.task('scripts', function() {
return gulp.src(jsFiles)
.pipe(concat('scripts.js'))
.pipe(gulp.dest(jsDest));
});
you just need to install and require gulp locally, you probably only installed it globally
At the command line
cd <project-root> && npm install --save-dev gulp
In your gulpfile.js
var gulp = require('gulp');
this is a different dependency than the command line dependency (that you installed globally). More specifically, it is the same NPM package, but the command line program will execute code usually from a different entry point in the NPM package then what require('X') will return.
If we go to the package.json file in the Gulp project on Github, it will tell the whole story:
{
"name": "gulp",
"description": "The streaming build system",
"version": "3.9.1",
"homepage": "http://gulpjs.com",
"repository": "gulpjs/gulp",
"author": "Fractal <contact#wearefractal.com> (http://wearefractal.com/)",
"tags": [ ],
"files": [
// ...
],
"bin": {
"gulp": "./bin/gulp.js"
},
"man": "gulp.1",
"dependencies": {
// ...
},
"devDependencies": {
// ...
},
"scripts": {
"prepublish": "marked-man --name gulp docs/CLI.md > gulp.1",
"lint": "eslint . && jscs *.js bin/ lib/ test/",
"pretest": "npm run lint",
},
"engines": {
"node": ">= 0.9"
},
"license": "MIT"
}
so at the command line:
$ gulp default
will execute this:
"bin": {
"gulp": "./bin/gulp.js"
},
on the other hand, require('gulp') in your code will return the value of this:
https://github.com/gulpjs/gulp/blob/master/index.js
normally we see this in a package.json file as:
"main": "index.js"
but since this is the default, they just omitted it (which is dumb IMO, better to be explicit, but they aren't the first project I have seen take the lame shorthand route.).
Its occurs on Windows and usually one of the following fixes it:
If you didn't, run npm install gulp on the project folder, even if
you have gulp installed globally.
Normally, It isn't a problem on Windows, but it could be a issue with
the PATH. The package will try to get the PATH from the environment,
but you can override it by adding exec_args to your gulp settings.
For example, on Ubuntu:
"exec_args": {
"path": "/bin:/usr/bin:/usr/local/bin"
}
Hope It will be OK.
Source: https://github.com/NicoSantangelo/sublime-gulp/issues/12
in node's package.json I would like to reuse a command that I already have in a 'script'.
Here is the practical example
instead of (note the extra -w on the watch script):
"scripts": {
"test" : "./node_modules/mocha/bin/mocha --compilers coffee:coffee-script/register --recursive -R list",
"watch": "./node_modules/mocha/bin/mocha --compilers coffee:coffee-script/register --recursive -R list -w",
}
I would like to have something like
"scripts": {
"test" : "./node_modules/mocha/bin/mocha --compilers coffee:coffee-script/register --recursive -R list",
"watch": "npm run script test" + "-w",
}
which doesn't work (can't do string concats in json), but you should get what I would like
I know that npm scripts support:
- & (parallel execution)
- && (sequencial execution)
so maybe there is another option?
This can be done in npm#2.1.17. You don't specify your OS and the version of npm that you are using, but unless you have done something to update it, you are probably running npm#1.4.28 which does not support the syntax below.
On Linux or OSX you can update npm with sudo npm install -g npm#latest. See https://github.com/npm/npm/wiki/Troubleshooting#try-the-latest-stable-version-of-npm for a guide to updating npm on all platforms.
You should be able to do this by passing an additional argument to your script:
"scripts": {
"test": "mocha --compilers coffee:coffee-script/register --recursive -R list",
"watch": "npm run test -- -w"
}
I verified this using the following, simplified package.json:
{
"scripts": { "a": "ls", "b": "npm run a -- -l" }
}
Output:
$ npm run a
> # a /Users/smikes/src/github/foo
> ls
package.json
$ npm run b
> # b /Users/smikes/src/github/foo
> npm run a -- -l
> # a /Users/smikes/src/github/foo
> ls -l
total 8
-rw-r--r-- 1 smikes staff 55 4 Jan 05:34 package.json
$