Good day, I’m new to Gulp and Node Js, I’ve been getting this error (shown below), I’ve done some research and I’ve not found any fixes.
[Browserslist] Could not parse /Users/gendyblackman/Sites/blackmanimages/package.json. Ignoring it.
assert.js:269
throw err;
AssertionError [ERR_ASSERTION]: Task never defined: clean
at getFunction (/Users/gendyblackman/Sites/blackmanimages/node_modules/undertaker/lib/helpers/normalizeArgs.js:15:5)
at map (/Users/gendyblackman/Sites/blackmanimages/node_modules/arr-map/index.js:20:14)
at normalizeArgs (/Users/gendyblackman/Sites/blackmanimages/node_modules/undertaker/lib/helpers/normalizeArgs.js:22:10)
at Gulp.series (/Users/gendyblackman/Sites/blackmanimages/node_modules/undertaker/lib/series.js:13:14)
at Object.<anonymous> (/Users/gendyblackman/Sites/blackmanimages/gulpfile.js:115:9)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
Also, when I reinstall Gulp locally I get these errors, shown below.
npm ERR! file /Users/gendyblackman/Sites/blackmanimages/package.json
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected string in JSON at position 734 while parsing '{
npm ERR! JSON.parse "name": "blackmanimages",
npm ERR! JSON.parse "version'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/gendyblackman/.npm/_logs/2018-07-05T14_56_20_043Z-debug.log
Any help would be great.
Thanks,
Also, here's my Gulpfile.js
// Compiles all SASS files
gulp.task('scss', function () {
return gulp.src('source/scss/**/*.scss')
.pipe(plumber())
.pipe(scss({
style: 'compressed',
}))
.pipe(rename({
basename: 'main',
suffix: '.min',
}))
.pipe(gulp.dest('build/assets/css'))
.pipe(browserSync.stream());
});
//Optimizing Images
gulp.task('images', function (){
return gulp.src('source/img/**/*.+(png|jpg|gif|svg)')
.pipe(cache(imagemin({
interlaced: true
})))
.pipe(gulp.dest('build/assets/img'))
});
// Uglify js files
gulp.task('scripts', function () {
gulp.src('source/js/*.js')
.pipe(plumber())
.pipe(uglify())
.pipe(gulp.dest('build/assets/js'))
.pipe(browserSync.stream());
});
//Concat and Compress Vendor .js files
gulp.task('vendors', function () {
gulp.src(
[
'source/js/vendors/jquery.min.js',
'source/js/vendors/*.js',
])
.pipe(plumber())
.pipe(concat('vendors.js'))
.pipe(uglify())
.pipe(gulp.dest('build/assets/js'));
});
// Watch for changes
gulp.task('watch', function () {
//Serve files from the root of this project
browserSync.init({
server: {
baseDir: "./build",
},
notify: false
});
gulp.watch(styleSrc, ['scss']);
gulp.watch(scriptSrc, ['scripts']);
gulp.watch(vendorSrc, ['vendors']);
gulp.watch(['build/*.html', 'build/assets/css/*.css', 'build/assets/js/*.js', 'build/assets/js/vendors/*.js' , '/build/assets/img/*' , '/build/assets/img/'])
.on(' change ', browserSync.reload);
});
//use default task to launch Browsersync and watch JS files
gulp.task('default',gulp.series('clean',gulp.parallel('scss', 'scripts', 'vendors',`images`,`fonts`, 'watch'), function (){
console.log('Building files');
}));
gulp.task('default', [ 'sass', 'scripts', 'vendors', 'watch'], function () );
gulp.task('default', function (callback) {runSequence(['sass','browserSync', 'watch'],callback)});
package.json
{
"name": "blackmanimages",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.24.5",
"del": "^3.0.0",
"express": "^4.16.3",
"gulp": "github:gulpjs/gulp#4.0",
"gulp-autoprefixer": "^5.0.0",
"gulp-cache": "^1.0.2",
"gulp-compass": "^2.1.0",
"gulp-imagemin": "^4.1.0",
"gulp-mamp": "0.0.5",
"gulp-minify-css": "^1.2.4",
"gulp-plumber": "^1.2.0",
"gulp-rename": "^1.2.3",
"gulp-sass": "^4.0.1",
"gulp-sourcemaps": "^2.6.4",
"minimatch": "^3.0.2",
"mysql": "^2.15.0",
"run-sequence": "^2.2.1"
"gulp-concat": "^2.6.1",
"gulp-contrib-copy": "0.1.3",
"gulp-cssnano": "^2.1.3",
"gulp-scss": "^1.4.0",
"gulp-uglify": "^3.0.0",
"gulp-useref": "^3.1.5"
},
"dependencies": {}
}
Error:
JSON.parse package.json must be actual JSON
your package.json is right format JSON.
Check this line :
"run-sequence": "^2.2.1"
add , to end of this line.
You didn't define task clean but you call it:
gulp.task('default',gulp.series('clean',gulp.parall .....
You should remove it or create clean.
You require('gulp-cache') but you removed it from package.json.
Check enviroment variable NODE_ENV is production ?
If true, remove it. (because you don't install devDependencies if NODE_ENV is production)
Related
For some context, I'm trying to develop apps for Microsoft Teams. So I decided to follow the 'Hello World' project but I ran into an issue when generating the app package(a zip file). I'm on Win10
Here are my versions of node and gulp
$ gulp -v
CLI version: 2.2.0
Local version: 4.0.0
$ node -v
v12.14.1
My Error :(
$ gulp
assert.js:374
throw err;
^
AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (C:\Users\Comp\source\entitled\msteams-samples-hello-world-nodejs\node_modules\undertaker\lib\set-task.js:10:3)
at Gulp.task (C:\Users\Comp\source\entitled\msteams-samples-hello-world-nodejs\node_modules\undertaker\lib\task.js:13:8)
at Object.<anonymous> (C:\Users\Comp\source\entitled\msteams-samples-hello-world-nodejs\gulpfile.js:17:6)
at Module._compile (internal/modules/cjs/loader.js:955:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Module.require (internal/modules/cjs/loader.js:848:19)
at require (internal/modules/cjs/helpers.js:74:18)
at execute (C:\Users\Comp\AppData\Roaming\npm\node_modules\gulp-cli\lib\versioned\^4.0.0\index.js:36:18) {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: false,
expected: true,
operator: '=='
}
package.json
{
"name": "msteams-nodejs-hello-world",
"version": "1.0.0",
"description": "Microsoft Teams Node.js Hello World App. Start here to build your first app on the Teams platform.",
"scripts": {
"start": "node src/app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/OfficeDev/msteams-samples-hello-world-nodejs.git"
},
"author": "Microsoft Corp.",
"license": "MIT",
"bugs": {
"url": "https://github.com/OfficeDev/msteams-samples-hello-world-nodejs/issues"
},
"homepage": "https://learn.microsoft.com/en-us/microsoftteams/platform/get-started/get-started-nodejs",
"dependencies": {
"botbuilder": "^3.11.0",
"botbuilder-teams": "^0.1.6",
"config": "^1.28.1",
"express": "^4.16.2",
"faker": "^4.1.0",
"natives": "^1.1.6",
"node": "^10.13.0",
"pug": "^2.0.4"
},
"devDependencies": {
"del": "^3.0.0",
"gulp": "^4.0.0",
"gulp-install": "^1.1.0",
"gulp-zip": "^4.0.0"
}
}
gulpfile.js
var gulp = require('gulp');
var zip = require('gulp-zip');
var del = require('del');
gulp.task('clean', function() {
return del([
'manifest/**/*'
])
});
gulp.task('generate-manifest', function() {
gulp.src(['src/static/images/contoso*', 'src/manifest.json'])
.pipe(zip('helloworldapp.zip'))
.pipe(gulp.dest('manifest'));
});
gulp.task('default', ['clean', 'generate-manifest'], function() {
console.log('Build completed. Output in manifest folder');
});
I've read through some other articles with where I had to downgrade node and gulp but I've had no luck.
gulp.task('generate-manifest', function() {
return gulp.src(['src/static/images/contoso*', 'src/manifest.json']) // change here
.pipe(zip('helloworldapp.zip'))
.pipe(gulp.dest('manifest'));
});
gulp.task('default', gulp.series('clean', 'generate-manifest', function() { // change here
console.log('Build completed. Output in manifest folder');
}));
No need to downgrade gulp or node. You just need to use gulp4 syntax instead of gulp3.
I am trying to convert React.js web app to desktop app through Electron. Please find the error trace, scripts/start.js, and package.json. When I comment out require('../config/env'); it starts giving same error on const paths = require('../config/paths');
start.js
'use strict';
// Do this as the first thing so that any code reading it knows the right env.
process.env.BABEL_ENV = 'development';
process.env.NODE_ENV = 'development';
// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', err => {
throw err;
});
// Ensure environment variables are read.
require('../config/env');
const fs = require('fs');
const chalk = require('chalk');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const clearConsole = require('react-dev-utils/clearConsole');
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
const {
choosePort,
createCompiler,
prepareProxy,
prepareUrls,
} = require('react-dev-utils/WebpackDevServerUtils');
const openBrowser = require('react-dev-utils/openBrowser');
const paths = require('../config/paths');
const config = require('../config/webpack.config.dev');
const createDevServerConfig = require('../config/webpackDevServer.config');
const useYarn = fs.existsSync(paths.yarnLockFile);
const isInteractive = process.stdout.isTTY;
// Warn and crash if required files are missing
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
process.exit(1);
}
// Tools like Cloud9 rely on this.
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
const HOST = process.env.HOST || '0.0.0.0';
if (process.env.HOST) {
console.log(
chalk.cyan(
`Attempting to bind to HOST environment variable: ${chalk.yellow(
chalk.bold(process.env.HOST)
)}`
)
);
console.log(
`If this was unintentional, check that you haven't mistakenly set it in your shell.`
);
console.log(`Learn more here: ${chalk.yellow('bitLyLink')}`);
console.log();
}
// We attempt to use the default port but if it is busy, we offer the user to
// run on a different port. `choosePort()` Promise resolves to the next free port.
choosePort(HOST, DEFAULT_PORT)
.then(port => {
if (port == null) {
// We have not found a port.
return;
}
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
const appName = require(paths.appPackageJson).name;
const urls = prepareUrls(protocol, HOST, port);
// Create a webpack compiler that is configured with custom messages.
const compiler = createCompiler(webpack, config, appName, urls, useYarn);
// Load proxy config
const proxySetting = require(paths.appPackageJson).proxy;
const proxyConfig = prepareProxy(proxySetting, paths.appPublic);
// Serve webpack assets generated by the compiler over a web sever.
const serverConfig = createDevServerConfig(
proxyConfig,
urls.lanUrlForConfig
);
const devServer = new WebpackDevServer(compiler, serverConfig);
// Launch WebpackDevServer.
devServer.listen(port, HOST, err => {
if (err) {
return console.log(err);
}
if (isInteractive) {
clearConsole();
}
console.log(chalk.cyan('Starting the development server...\n'));
openBrowser(urls.localUrlForBrowser);
});
['SIGINT', 'SIGTERM'].forEach(function(sig) {
process.on(sig, function() {
devServer.close();
process.exit();
});
});
})
.catch(err => {
if (err && err.message) {
console.log(err.message);
}
process.exit(1);
});
package.json
{
"name": "utility-core",
"version": "0.1.0",
"private": true,
"main": "public/electron.js",
"homepage": "./",
"dependencies": {
"autoprefixer": "7.1.6",
"axios": "^0.18.0",
"babel-core": "6.26.0",
"babel-eslint": "7.2.3",
"babel-jest": "20.0.3",
"babel-loader": "7.1.2",
"babel-preset-react-app": "^3.1.1",
"babel-runtime": "6.26.0",
"bootstrap": "^4.1.3",
"case-sensitive-paths-webpack-plugin": "2.1.1",
"chalk": "1.1.3",
"concurrently": "^4.1.1",
"css-loader": "0.28.7",
"dotenv": "4.0.0",
"dotenv-expand": "4.2.0",
"electron-is-dev": "^1.1.0",
"eslint": "4.10.0",
"eslint-config-react-app": "^2.1.0",
"eslint-loader": "1.9.0",
"eslint-plugin-flowtype": "2.39.1",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-jsx-a11y": "5.1.1",
"eslint-plugin-react": "7.4.0",
"extract-text-webpack-plugin": "3.0.2",
"file-loader": "1.1.5",
"fs-extra": "3.0.1",
"html-webpack-plugin": "2.29.0",
"jest": "20.0.4",
"jquery": "^3.4.1",
"mdbreact": "^4.15.0",
"object-assign": "4.1.1",
"papaparse": "^4.6.0",
"postcss-flexbugs-fixes": "3.2.0",
"postcss-loader": "2.0.8",
"promise": "8.0.1",
"raf": "3.4.0",
"react": "^16.4.1",
"react-dev-utils": "^5.0.1",
"react-dom": "^16.4.1",
"react-file-reader": "^1.1.4",
"react-router-dom": "^4.2.0",
"react-spinners": "^0.4.6",
"resolve": "1.6.0",
"style-loader": "0.19.0",
"sw-precache-webpack-plugin": "0.11.4",
"universal-cookie": "^3.0.4",
"url-loader": "0.6.2",
"wait-on": "^3.2.0",
"webpack": "3.8.1",
"webpack-dev-server": "2.9.4",
"webpack-manifest-plugin": "1.3.2",
"whatwg-fetch": "2.0.3"
},
"scripts": {
"start": "node scripts/start.js",
"build": "node scripts/build.js",
"test": "node scripts/test.js --env=jsdom",
"electron-dev": "concurrently \" cross-env BROWSER=none npm run start\" \"wait-on http://localhost:3000 && electron .\"",
"electron-pack": "build -c.extraMetadata.main=build/electron.js",
"preelectron-pack": "npm run build"
},
"devDependencies": {
"cross-env": "^5.2.0",
"csv-loader": "^3.0.2",
"electron": "^1.8.8",
"electron-builder": "^20.44.4",
"electron-installer-windows": "^2.0.0",
"electron-packager": "^8.7.2"
},
"jest": {
"collectCoverageFrom": [
"src/**/*.{js,jsx,mjs}"
],
"setupFiles": [
"<rootDir>/config/polyfills.js"
],
"testMatch": [
"<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
"<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
],
"testEnvironment": "node",
"testURL": "http://localhost",
"transform": {
"^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
"^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
},
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
],
"moduleNameMapper": {
"^react-native$": "react-native-web"
},
"moduleFileExtensions": [
"web.js",
"js",
"json",
"web.jsx",
"jsx",
"node",
"mjs"
]
},
"babel": {
"presets": [
"env",
"react-app"
],
"plugins": []
},
"eslintConfig": {
"extends": "react-app"
},
"author": "Zain Ul Abideen",
"license": "ISC",
"build": {
"extends": null,
"appId": "com.example.utility-core",
"files": [
"build/**/*",
"node_modules/**/*",
"./public/electron.js"
],
"directories": {
"buildResources": "assets"
}
}
}
Error
D:\Import Utility\fc-import-utility\utility-core>npm run electron-dev
> utility-core#0.1.0 electron-dev D:\Import Utility\fc-import-utility\utility-core
> concurrently " cross-env BROWSER=none npm run start" "wait-on http://localhost:3000 && electron ."
[0]
[0] > utility-core#0.1.0 start D:\Import Utility\fc-import-utility\utility-core
[0] > node scripts/start.js
[0]
[0] internal/modules/cjs/loader.js:613
throw err;
[0] ^
[0]
[0] Error: Cannot find module '../config/paths'
[0] Require stack:
[0] - D:\Import Utility\fc-import-utility\utility-core\scripts\start.js
[0] at Function.Module._resolveFilename (internal/modules/cjs/loader.js:610:15)
[0] at Function.Module._load (internal/modules/cjs/loader.js:526:27)
[0] at Module.require (internal/modules/cjs/loader.js:666:19)
[0] at require (internal/modules/cjs/helpers.js:16:16)
[0] at Object.<anonymous> (D:\Import Utility\fc-import-utility\utility-core\scripts\start.js:30:15)
[0] at Module._compile (internal/modules/cjs/loader.js:759:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
[0] at Module.load (internal/modules/cjs/loader.js:628:32)
[0] at Function.Module._load (internal/modules/cjs/loader.js:555:12)
[0] at Function.Module.runMain (internal/modules/cjs/loader.js:822:10)
[0]
[0] npm ERR! Windows_NT 10.0.17134
[0] npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\HP\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "start"
[0] npm ERR! node v12.2.0
[0] npm ERR! npm v3.8.6
npm ERR! code ELIFECYCLE
[0] npm ERR! utility-core#0.1.0 start: `node scripts/start.js`
[0] npm ERR! Exit status 1
[0] npm ERR!
[0] npm ERR! Failed at the utility-core#0.1.0 start script 'node scripts/start.js'.
[0] npm ERR! Make sure you have the latest version of node.js and npm installed.
[0] npm ERR! If you do, this is most likely a problem with the utility-core package,
[0] npm ERR! not with npm itself.
[0] npm ERR! Tell the author that this fails on your system:
[0] npm ERR! node scripts/start.js
[0] npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs utility-core
[0] npm ERR! Or if that isn't available, you can get their info via:
[0] npm ERR! npm owner ls utility-core
[0] npm ERR! There is likely additional logging output above.
[0]
[0] npm ERR! Please include the following file with any support request:
[0] npm ERR! D:\Import Utility\fc-import-utility\utility-core\npm-debug.log
[0] cross-env BROWSER=none npm run start exited with code 1
I've inherited a rather unusual website that is a hybrid of C# and Node JS (using TypeScript). We have a continuous integration environment set up on Azure DevOps to build the website and deploy it to a test environment. We've not had to build the website since March, and now the build process has suddenly broken. We had to change the reference to 'gulp' in package.json from "github:gulpjs/gulp#4.0" (which no longer exists) to "github:gulpjs/gulp#71c094a51c7972d26f557899ddecab0210ef3776", but now the step of the build process that calls gulp ("node node_modules\gulp\bin\gulp.js package") is failing with the following error (this is from the DevOps build log):
2018-12-04T22:38:48.9501268Z [22:38:48] TypeError in plugin "gulp-babel"
2018-12-04T22:38:48.9501465Z Message:
2018-12-04T22:38:48.9501806Z Path must be a string. Received undefined
If I run "node node_modules\gulp\bin\gulp.js package" locally I get the following:
[11:54:45] Error: TypeScript error: node_modules/#angular/router/src/router_module.d.ts(140,41): Error TS1110: Type expected.
at formatError (C:\.....\node_modules\gulp\node_modules\gulp-cli\lib\versioned\^4.0.0\format-error.js:20:10)
at Gulp.<anonymous> (C:\.....\node_modules\gulp\node_modules\gulp-cli\lib\versioned\^4.0.0\log\events.js:31:15)
at emitOne (events.js:120:20)
at Gulp.emit (events.js:210:7)
at Object.error (C:\.....\node_modules\undertaker\lib\helpers\createExtensions.js:61:10)
at handler (C:\.....\node_modules\now-and-later\lib\mapSeries.js:43:14)
at f (C:\.....\node_modules\once\once.js:25:25)
at f (C:\.....\node_modules\once\once.js:25:25)
at tryCatch (C:\.....\node_modules\async-done\index.js:24:15)
at done (C:\.....\node_modules\async-done\index.js:40:12)
This link - https://github.com/babel/gulp-babel/issues/154 - seems to suggest a problem with browserify (or at least an incompatibility between browserify and babel-core)? The only suggestion is to drop the use of browserify. The mystery to me is why this worked previously but is now failing when all we've changed is the reference to gulp.
Could anyone explain to me what is causing the error and how to resolve it? Any help will be greatly appreciated.
The gulp task that is raising the error is this:
gulp.task("bundle", function () {
return browserify({
basedir: '.',
debug: true,
entries: [config.appMain],
cache: {},
packageCache: {}
})
.plugin(tsify)
.bundle()
.pipe(source('app.bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(babel({ presets: ['env'] }))
.pipe(uglify())
.pipe(sourcemaps.write('./', { includeContent: false, sourceRoot: '../' }))
.pipe(gulp.dest(config.jsDest));
});
config.appMain = "App/main.ts"
config.jsDest = "./wwwroot/js"
The relevant 'requires' at the top of gulpfile.js are:
var gulp = require('gulp');
var browserify = require("browserify");
var tsify = require("tsify");
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var sourcemaps = require('gulp-sourcemaps');
var babel = require('gulp-babel');
var uglify = require("gulp-uglify");
var config = require('./gulp.config')();
The package.json devDependencies versions are:
"#types/core-js": "^0.9.34",
"#types/node": "^6.0.45",
"babel-preset-env": "^1.7.0",
"browserify": "^16.2.3",
"concurrently": "^3.4.0",
"del": "^2.2.2",
"gulp": "github:gulpjs/gulp#71c094a51c7972d26f557899ddecab0210ef3776",
"gulp-babel": "^6.1.2",
"gulp-clean": "^0.3.2",
"gulp-clean-css": "^3.0.4",
"gulp-concat": "^2.6.1",
"gulp-copy": ">=0.0.2",
"gulp-cssmin": "^0.2.0",
"gulp-htmlmin": "^3.0.0",
"gulp-load-plugins": "^1.3.0",
"gulp-rename": ">=1.2.2",
"gulp-rimraf": ">=0.2.0",
"gulp-sourcemaps": "^2.6.0",
"gulp-uglify": "^3.0.0",
"gulp-util": "^3.0.8",
"gulp-watch": ">=4.3.9",
"jasmine-core": "2.4.1",
"merge-stream": "^1.0.1",
"nodemon": "^1.11.0",
"tsify": "^3.0.1",
"tslint": "^3.15.1",
"typescript": "^2.0.0",
"typings": "^1.3.2",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^2.0.0"
I've tried using babelify, so the gulp task becomes:
gulp.task("bundle", function () {
return browserify({
basedir: '.',
debug: true,
entries: [config.appMain],
cache: {},
packageCache: {}
})
.transform(babelify, { presets: ['env'] })
.plugin(tsify)
.bundle()
.pipe(source('app.bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write('./', { includeContent: false, sourceRoot: '../' }))
.pipe(gulp.dest(config.jsDest));
});
but I get exactly the same error when I execute "node node_modules\gulp\bin\gulp.js package" locally.
Please let me know if you need any more details or code. Thanks for any help you can give.
A colleague of mine worked this out. The solution is, of course, to use babelify. However, I got the implementation wrong. The usage in the gulp task that works is:
gulp.task("bundle", function () {
return browserify({
transform: [["babelify", { "presets": ["#babel/preset-env"] }]],
basedir: '.',
debug: true,
entries: [config.appMain],
cache: {},
packageCache: {}
})
.plugin(tsify)
.bundle()
.pipe(source('app.bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(babel({ presets: ["#babel/preset-env"] }))
.pipe(uglify())
.pipe(sourcemaps.write('./', { includeContent: false, sourceRoot: '../' }))
.pipe(gulp.dest(config.jsDest));
});
The packages and versions used in package.json devDependencies are:
"browserify": "^16.2.3",
"#babel/core": "^7.2.0",
"#babel/preset-env": "^7.2.0",
"babelify": "^10.0.0",
"gulp-babel": "8.0.0",
When hosting my app I get the following errors
2018-07-03T23:32:25.175363+00:00 heroku[web.1]: Starting process with command `npm start`
2018-07-03T23:32:28.093779+00:00 heroku[web.1]: State changed from starting to crashed
2018-07-03T23:32:27.719911+00:00 app[web.1]:
2018-07-03T23:32:27.719929+00:00 app[web.1]: > doombot#1.0.0 start /app
2018-07-03T23:32:27.719931+00:00 app[web.1]: > node src/server/dist/server.js
2018-07-03T23:32:27.719932+00:00 app[web.1]:
2018-07-03T23:32:27.942441+00:00 app[web.1]: module.js:545
2018-07-03T23:32:27.942444+00:00 app[web.1]: throw err;
2018-07-03T23:32:27.942446+00:00 app[web.1]: ^
2018-07-03T23:32:27.942447+00:00 app[web.1]:
2018-07-03T23:32:27.942449+00:00 app[web.1]: Error: Cannot find module '/app/src/server/dist/server.js'
2018-07-03T23:32:27.942451+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:543:15)
2018-07-03T23:32:27.942453+00:00 app[web.1]: at Function.Module._load (module.js:470:25)
2018-07-03T23:32:27.942454+00:00 app[web.1]: at Function.Module.runMain (module.js:690:10)
2018-07-03T23:32:27.942456+00:00 app[web.1]: at startup (bootstrap_node.js:194:16)
2018-07-03T23:32:27.942457+00:00 app[web.1]: at bootstrap_node.js:666:3
2018-07-03T23:32:27.960851+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-07-03T23:32:27.961370+00:00 app[web.1]: npm ERR! errno 1
2018-07-03T23:32:27.965212+00:00 app[web.1]: npm ERR! doombot#1.0.0 start: `node src/server/dist/server.js`
2018-07-03T23:32:27.966189+00:00 app[web.1]: npm ERR! Exit status 1
2018-07-03T23:32:27.967067+00:00 app[web.1]: npm ERR!
2018-07-03T23:32:27.967873+00:00 app[web.1]: npm ERR! Failed at the doombot#1.0.0 start script.
2018-07-03T23:32:27.968281+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-07-03T23:32:28.070076+00:00 heroku[web.1]: Process exited with status 1
2018-07-03T23:32:28.010680+00:00 app[web.1]:
2018-07-03T23:32:28.010886+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-07-03T23:32:28.011019+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-07-03T23_32_27_989Z-debug.log
This is my package.json file
{
"name": "doombot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"tsc": "tsc",
"start": "node src/server/dist/server.js",
"heroku-postbuild": "webpack --config webpack.prod.js; tsc -p ./tsconfig.json",
"server": "nodemon src/server/lib/server.ts",
"client": "webpack-dev-server --open --config webpack.dev.js",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"keywords": [],
"author": "",
"license": "ISC",
"engines": {
"npm": "6.0.0",
"node": "9.9.0"
},
"dependencies": {
"#types/express": "^4.11.1",
"antd": "^3.6.4",
"app-root-path": "^2.1.0",
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"cors": "^2.8.4",
"express": "^4.16.3",
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"typescript": "2.9.1"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-plugin-import": "^1.8.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"clean-webpack-plugin": "^0.1.19",
"concurrently": "^3.5.1",
"css-loader": "^0.28.11",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.7.0",
"html-webpack-plugin": "^3.2.0",
"nodemon": "^1.17.3",
"style-loader": "^0.20.3",
"uglifyjs-webpack-plugin": "^1.2.7",
"webpack": "^4.5.0",
"webpack-cli": "^2.0.14",
"webpack-dev-server": "^3.1.3",
"webpack-merge": "^4.1.3"
}
}
webpack.common.js
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/client/index.js',
plugins: [new CleanWebpackPlugin(['build']), new HtmlWebpackPlugin()],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
]
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'build')
}
};
webpack.dev.js
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const path = require('path');
module.exports = merge(common, {
mode: 'development',
devtool: 'inline-source-map',
devServer: {
contentBase: './build',
port: 3000,
open: true,
proxy: {
'/api': 'http://localhost:4040'
}
}
});
webpack.prod.js
const webpack = require('webpack');
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const path = require('path');
module.exports = merge(common, {
mode: 'production',
devtool: 'source-map',
plugins: [
new UglifyJSPlugin({
sourceMap: true
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
});
and my tsconfig file
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"pretty": true,
"sourceMap": true,
"target": "es6",
"outDir": "./src/server/dist", // creates the dist directory & places compiles files here
"baseUrl": "./src/server/lib"
},
"include": [
"./src/server/lib/**/*.ts" // specifies that we should include all ts files within lib
],
"exclude": ["node_modules"]
}
If I understand correctly, this is not appearing due to it not building properly. My question is how can I build and run my app the correct way?
If you would like to see my entire code, you can find it here - https://github.com/albertogodinez/dooms-data
You're missing quite a few steps. Let's backtrack a bit.
You're telling Heroku that to start your app, it should run node src/server/dist/server.js (because you specify that as the start script in your package.json). However, server.js does not exist on Heroku, there's only server.ts (i.e. the TypeScript file).
Thus, you'll have to tell Heroku to convert your TypeScript file to Javascript - right now, you're only telling it to build your client (i.e. through webpack in the heroku-postbuild script). To fix this, you can change that script to "webpack --mode production; tsc --project=tsconfig.json",
However, that won't work either as the TypeScript compiler is not installed on Heroku. Therefore, be sure to add typescript to your dependencies (note that IIRC, Heroku does not install devDependencies, so either make it a regular dependency or tell Heroku to install devDependencies as well.
Even if your server then runs correctly, it only serves your API. If you also want your client to be reachable, you have to tell Express to serve it. You could do that something like this:
.
app.use(
express.static(
path.join(__dirname, '../../compiled_frontend'),
{ index: false },
),
);
That, I think, should do the trick, but obviously more could be wrong. Coincidentally, I'm working on an app with a very similar setup, and it's open source - so feel free to give it a look if you need inspiration.
I'm trying to export my firebase app so I can call it inside of mocha test specs as well as within the source code I'm trying to test.
My Mocha test spec looks like this:
import Vue from 'vue'
import Edit from '#/components/Edit'
import filedata from '../../../static/filedata.js'
import submitFile from '../../../helpers/submitFile.js'
import firebaseapp from '../../../src/db.js'
var db = firebaseapp.database()
var storage = firebaseapp.storage()
describe('Edit.vue', () => {
it('should let me add files without choosing a category', () => {
// add files to appear on the homepage
var Constructor = Vue.extend(Edit)
var vm = new Constructor().$mount()
console.log(filedata + ' is the file data')
var ref = storage.ref('categories')
console.log(ref)
submitFile(filedata)
}) ...
And the submitFile file looks like this:
var firebaseapp = require('../src/db.js')
console.log('the app is: ' + firebaseapp)
var db = firebaseapp.database()
var storage = firebaseapp.storage()
module.exports = function(files){
// is the function being called from the test environment?
if(files){
console.log(files)
}
else {
// function called from src -- files were null
var files = this.$refs.upload.uploadFiles;
}
var storageRef = storage.ref();
var pdfsRef = storageRef.child('files');
// var self = this;
console.log('the files length is ' + files.length)
files.forEach(function(file){
var file = file['raw'];
var name = file['name']
var fileref = storageRef.child(name);
var uploadTask = fileref.put(file);
uploadTask.then(function(snapshot){
console.log('uploaded');
var url = snapshot.downloadURL;
self.gettext(url, name);
});
try {
uploadTask.on('state_changed', function(snapshot){
// Observe state change events such as progress, pause, and resume
// Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
self.uploadProgress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log(self.uploadProgress + ' is the upload progress.');
switch (snapshot.state) {
case app.storage.TaskState.PAUSED: // or 'paused'
console.log('Upload is paused');
break;
case app.storage.TaskState.RUNNING: // or 'running'
console.log('Upload is running');
break;
}
}, function(error) {
// Handle unsuccessful uploads
}, function() {
// Handle successful uploads on complete
// For instance, get the download URL: https://firebasestorage.googleapis.com/...
var downloadURL = uploadTask.snapshot.downloadURL;
});
}
catch(e){
console.log(e)
}
})
}
Lastly, here's what db.js looks like:
var Firebase = require('firebase')//import Firebase from 'firebase'
var config = {
...
};
var app = Firebase.initializeApp(config) /// USED TO BE CONST APP
export default app
What's very strange is that when I run npm run unit, I get an error telling me that const is not recognized.
SyntaxError: Unexpected token 'const'
at webpack:///src/db.js~:11:0 <- index.js:38182
So I went through my db.js file and changed const to var, and I'm getting the exact same error*, no matter how I change the file.
Does anyone have any idea what could be going on?
Here's my package.json
{
...
"private": true,
"scripts": {
"dev": "node build/dev-server.js",
"start": "node build/dev-server.js",
"build": "node build/build.js",
"unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run",
"e2e": "node test/e2e/runner.js",
"prepare": "node ./helpers/gettestfiles.js",
"test": "npm run prepare && npm run unit && npm run e2e && cd ../neuhold-front && npm run unit && npm run e2e",
"deploy": "npm run build && firebase deploy"
},
"dependencies": {
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",
"element-ui": "^1.4.2",
"firebase": "^4.3.0",
"pdfjs-dist": "^1.9.450",
"vue": "^2.3.3",
"vue-awesome": "^2.3.1",
"vuefire": "^1.4.3"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
"babel-core": "^6.22.1",
"babel-loader": "^7.1.1",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"babel-register": "^6.22.0",
"chalk": "^2.0.1",
"connect-history-api-fallback": "^1.3.0",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.0",
"cssnano": "^3.10.0",
"eventsource-polyfill": "^0.9.6",
"express": "^4.14.1",
"extract-text-webpack-plugin": "^2.0.0",
"file-loader": "^0.11.1",
"friendly-errors-webpack-plugin": "^1.1.3",
"html-webpack-plugin": "^2.28.0",
"http-proxy-middleware": "^0.17.3",
"webpack-bundle-analyzer": "^2.2.1",
"cross-env": "^5.0.1",
"karma": "^1.4.1",
"karma-coverage": "^1.1.1",
"karma-mocha": "^1.3.0",
"karma-phantomjs-launcher": "^1.0.2",
"karma-phantomjs-shim": "^1.4.0",
"karma-sinon-chai": "^1.3.1",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.31",
"karma-webpack": "^2.0.2",
"lolex": "^1.5.2",
"mocha": "^3.2.0",
"chai": "^3.5.0",
"sinon": "^2.1.0",
"sinon-chai": "^2.8.0",
"inject-loader": "^3.0.0",
"babel-plugin-istanbul": "^4.1.1",
"phantomjs-prebuilt": "^2.1.14",
"chromedriver": "^2.27.2",
"cross-spawn": "^5.0.1",
"nightwatch": "^0.9.12",
"selenium-server": "^3.0.1",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"opn": "^5.1.0",
"optimize-css-assets-webpack-plugin": "^2.0.0",
"ora": "^1.2.0",
"rimraf": "^2.6.0",
"url-loader": "^0.5.8",
"vue-loader": "^12.1.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.3.3",
"webpack": "^2.6.1",
"webpack-dev-middleware": "^1.10.0",
"webpack-hot-middleware": "^2.18.0",
"webpack-merge": "^4.1.0"
},
"engines": {
"node": ">= 4.0.0",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
build/webpack.dev.conf.js
var utils = require('./utils')
var webpack = require('webpack')
var config = require('../config')
var merge = require('webpack-merge')
var baseWebpackConfig = require('./webpack.base.conf')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
// add hot-reload related code to entry chunks
Object.keys(baseWebpackConfig.entry).forEach(function (name) {
baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
})
module.exports = merge(baseWebpackConfig, {
module: {
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap })
},
// cheap-module-eval-source-map is faster for development
devtool: '#cheap-module-eval-source-map',
plugins: [
new webpack.DefinePlugin({
'process.env': config.dev.env
}),
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
// https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true
}),
new FriendlyErrorsPlugin()
]
})
To show that I'm not mistakenly editing different repos ...
macbook001:docu-repo josephadmin$ cd neuhold-back
macbook001:neuhold-back josephadmin$ cd ..
macbook001:docu-repo josephadmin$ cd neuhold-back/src
macbook001:src josephadmin$ ls
App.vue assets components db.js db.js~ main.js
macbook001:src josephadmin$ cat db.js
/* eslint-disable */
import Firebase from 'firebase'
var config = {
...
};
var app = Firebase.initializeApp(config)
export default app
macbook001:src josephadmin$ cd ../ && npm run unit
> neuhold-back#0.1.0 unit /Users/josephadmin/production/docu-repo/neuhold-back
> cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run
28 08 2017 12:45:41.353:INFO [karma]: Karma v1.7.0 server started at http://0.0.0.0:9876/
28 08 2017 12:45:41.357:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
28 08 2017 12:45:41.376:INFO [launcher]: Starting browser PhantomJS
28 08 2017 12:45:42.504:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket ... with id 994129
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
SyntaxError: Unexpected token 'const'
at webpack:///src/db.js~:11:0 <- index.js:38108
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 0 of 0 ERROR (0.65 secs / 0 secs)
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 0 of 0 ERROR (0 secs / 0 secs)
=============================== Coverage summary ===============================
Statements : 100% ( 0/0 )
Branches : 100% ( 0/0 )
Functions : 100% ( 0/0 )
Lines : 100% ( 0/0 )
================================================================================
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "unit"
npm ERR! node v7.10.0
npm ERR! npm v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! neuhold-back#0.1.0 unit: `cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the neuhold-back#0.1.0 unit script 'cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the neuhold-back package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs neuhold-back
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls neuhold-back
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/josephadmin/.npm/_logs/2017-08-28T10_45_43_361Z-debug.log
macbook001:neuhold-back josephadmin$
From the looks of the error thrown, this seems like a problem with PhantomJS cache. Check this Stack Overflow post right here.