var gulp = require('gulp');
var browserify = require('browserify');
var reactify = require('reactify');
gulp.task('react', function(){
console.log("gulp is runnung");
});
gulp.src('src/App.js')
.pipe(browserify({
insertGlobals: false,
debug: true,
transform: [reactify]
}))
.pipe(gulp.dest('./dist/js'));
gulp.task("watch", function(){
gulp.watch(["src/**/*.js"," src/**/*.jsx"], ["react"]);
})
gulp.task("default", ["watch"]);
module.exports = gulp;
New to Gulp not sure what to do here
I installed every dependency
gulp,
reactify and browserify
.pipe(gulp.dest('./dist/js'));
^
TypeError: gulp.src(...).pipe(...).pipe is not a function
at Object.<anonymous> (C:\Users\geilkea\Desktop\my-project\src\gulpfile.js:16:2)
at Module._compile (node:internal/modules/cjs/loader:1083:30)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)
at Module.load (node:internal/modules/cjs/loader:948:32)
at Function.Module._load (node:internal/modules/cjs/loader:789:14)
at Module.require (node:internal/modules/cjs/loader:972:19)
at require (node:internal/modules/cjs/helpers:88:18)
at [eval]:1:12
at Script.runInThisContext (node:vm:132:18)
at Object.runInThisContext (node:vm:309:38)
This is the error im getting do I have to require something else?
Related
I am following the documentation at https://jestjs.io/docs/getting-started
I have a directory structure like...
learnjest/sum.js
learnjest/sum.test.js
learnjest/package.json
learnjest/package-lock.json
learnjest/node_modules
My sum.js, sum.test.js and package.json are all exact copies of the code in the "Getting Started" example.
sum.js:
function sum(a, b) {
return a + b;
}
module.exports = sum;
sum.test.js:
const sum = require('./sum');
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
package.json:
{
"scripts": {
"test": "jest"
}
}
When I run npm test, I see...
> # test /path/to/learnjest
> jest
/path/to/learnjest/node_modules/jest/node_modules/jest-cli/build/cli/index.js:161
if (error?.stack) {
^
SyntaxError: Unexpected token '.'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/path/to/learnjest/node_modules/jest/node_modules/jest-cli/build/index.js:13:12)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
npm ERR! Test failed. See above for more details.
__drush_ps1: command not found
__git_ps1: command not found
The problem can occur if you are using an older version of Node.js. For example, I had the same problem with version 12. After I upgraded Node.js version to 19.2 the error was fixed.
I can't seem to get gulp to work, it wont compile and launh the local server as it should. I have tried downgrading, uninstalling upgrading and nothing seem to work. Am i missing something?
Error:
assert.js:385
throw err;
^
AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (C:\Users\thebl\fusion\node_modules\undertaker\lib\set-task.js:10:3)
at Gulp.task (C:\Users\thebl\fusion\node_modules\undertaker\lib\task.js:13:8)gulpfile.js:32:6)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at execute (C:\Users\thebl\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: '=='
}
Code:
'use strict';
var gulp = require('gulp'),
sass = require('gulp-sass'),
browserSync = require('browser-sync');
gulp.task('sass', function() {
return gulp.src('./css*.scss')
.pipe(sass().on('error',sass.logError))
.pipe(gulp.dest('./css'));
});
gulp.task('sass:watch', function() {
gulp.watch('./css/*.scss', ['sass']);
});
gulp.task('browser-sync', function() {
var files = [
'./*.html',
'./css/*.css',
'./js/*.js',
'./img/*.{png,jpg,gif}'
];
browserSync.init(files, {
server: {
baseDir: './'
},
});
});
gulp.task('default', ['browser-sync'], function() {
gulp.start('sass:watch');
});
I am trying out an electron app which should point to our website, so I am trying one of the tutorials.. Unfortunately, when I start the app, I get the following error :
Error log :
akshay#akshay-mint-desktop ~/electron_tutorial_one $ npm start
> electron_tutorial_one#1.0.0 start /home/akshay/electron_tutorial_one
> electron .
App threw an error during load
Error: Cannot find module 'app'
at Module._resolveFilename (module.js:455:15)
at Function.Module._resolveFilename (/home/akshay/electron_tutorial_one/node_modules/electron-prebuilt/dist/resources/electron.asar/common/reset-search-paths.js:35:12)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/akshay/electron_tutorial_one/index.js:2:11)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Cannot find module 'app'
at Module._resolveFilename (module.js:455:15)
at Function.Module._resolveFilename (/home/akshay/electron_tutorial_one/node_modules/electron-prebuilt/dist/resources/electron.asar/common/reset-search-paths.js:35:12)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/akshay/electron_tutorial_one/index.js:2:11)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
^Cakshay#akshay-mint-desktop ~/electron_tutorial_one $
index.js :
// Require the libraries used in the app
var app = require('app'),
BrowserWindow = require('browser-window');
require('crash-reporter').start();
var mainWindow = null;
// Kill the app when all windows are closed
app.on('mainWindow-all-closed', function() {
if (process.platform != 'darwin')
app.quit();
});
app.on('ready', function() {
// Create the main window for the app
mainWindow = new BrowserWindow({
"min-width" : 800,
"min-height" : 600,
fullscreen : true,
resizable : true,
"use-content-size" : true
});
// Load in our content
mainWindow.loadUrl('file://' + __dirname + '/index.html');
// This is required for now due to https://github.com/atom/electron/issues/1117
mainWindow.openDevTools();
mainWindow.closeDevTools();
// Ensure that garbage collection occurs when the window is closed
mainWindow.on('closed', function() {
mainWindow = null;
});
});
package.json :
{
"name": "electron_tutorial_one",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "electron ."
},
"author": "",
"license": "ISC",
"devDependencies": {
"electron-prebuilt": "^1.4.13"
}
}
Instead of
// Require the libraries used in the app
var app = require('app'), BrowserWindow = require('browser-window');
you should use
const { app, BrowserWindow } = require('electron')
You've used a really old example. Electron modules are collected under 'electron' in 0.35.0 more then two years ago ;)
From release notes:
Add electron module which includes all public APIs.
You'd better use tutorials from electron docs:
https://www.electronjs.org/docs/tutorial/quick-start
https://github.com/electron/electron-quick-start
I have a Phoenix app and am trying to get Mocha wired up for javascript unit tests. I want to test module 'Two', that imports module 'One' but I can't figure out how to configure Mocha to find module one.
Here is the test code:
web/static/js/one.js
export var One = 1;
web/static/js/two.js
import {One} from "web/static/js/one";
export var Two = function () {return One + One;}
> test/js/two_test.js
import assert from 'assert';
import {Two} from "../../web/static/js/two";
describe('Two()', function() {
it('returns value 2', function () {
assert.equal(2, Two());
});
});
Here is the output when I run npm test
home:~/elixir/optitrue$ npm test
> # test /home/jon/elixir/optitrue
> mocha --compilers js:babel-register test/js/**/*.js
module.js:457
throw err;
^
Error: Cannot find module 'web/static/js/one'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (two.js:1:1)
at Module._compile (module.js:556:32)
at loader (/home/jon/elixir/optitrue/node_modules/babel-register/lib/node.js:148:5)
at Object.require.extensions.(anonymous function) [as .js] (/home/jon/elixir/optitrue/node_modules/babel-register/lib/node.js:158:7)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (two_test.js:2:1)
at Module._compile (module.js:556:32)
at loader (/home/jon/elixir/optitrue/node_modules/babel-register/lib/node.js:148:5)
at Object.require.extensions.(anonymous function) [as .js] (/home/jon/elixir/optitrue/node_modules/babel-register/lib/node.js:158:7)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at /home/jon/elixir/optitrue/node_modules/mocha/lib/mocha.js:220:27
at Array.forEach (native)
at Mocha.loadFiles (/home/jon/elixir/optitrue/node_modules/mocha/lib/mocha.js:217:14)
at Mocha.run (/home/jon/elixir/optitrue/node_modules/mocha/lib/mocha.js:485:10)
at Object.<anonymous> (/home/jon/elixir/optitrue/node_modules/mocha/bin/_mocha:403:18)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.runMain (module.js:590:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
brunch.config
exports.config = {
// See http://brunch.io/#documentation for docs.
files: {
javascripts: {
joinTo: "js/app.js"
},
stylesheets: {
joinTo: "css/app.css"
},
templates: {
joinTo: "js/app.js"
}
},
conventions: {
assets: /^(web\/static\/assets)/
},
// Phoenix paths configuration
paths: {
watched: [
"web/static",
"test/static"
],
// Where to compile files to
public: "priv/static"
},
// Configure your plugins
plugins: {
babel: {
// Do not use ES6 compiler in vendor code
ignore: [/web\/static\/vendor/]
}
},
modules: {
autoRequire: {
"js/app.js": ["web/static/js/app"]
}
},
npm: {
enabled: true,
whitelist: ["phoenix", "phoenix_html"]
}
};
The error is quite clear:
Error: Cannot find module 'web/static/js/one'
Meaning the path you provided doesn't work, try using a relative paths:
import {One} from "./one";
My test file's code is:
var React = require('react');
var {shalow} = require('enzyme')
var {SearchBox} = require('../static/js/functions')
var expect = require('expect');
describe('Test', function(){
it('1', function(){
expect(true).toEqual(true);
});
});
This is my React class in functions.js
var SearchBox = React.createClass({
render: function() {
return (
<div>
<SearchList data={this.props.data}></SearchList>
<li>
<button id="previous_page" className="previous_page" onClick={back}>Previous</button>
<button id="next_page" className="next_page" onClick={next}>Next</button>
</li>
</div>
)
}
});
It is working fine but I want to write tests and when I run it, it outputs the following error :
irtza#irtza-Lenovo-G50-70:~/Desktop/Kamal Hasan/pedialink$ mocha
./js_test/*.js
/home/irtza/Desktop/Kamal Hasan/pedialink/static/js/functions.js:39
,
^ SyntaxError: Unexpected token <
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:511:25)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Module.require (module.js:466:17)
at require (internal/module.js:20:19)
at Object. (/home/irtza/Desktop/Kamal Hasan/pedialink/js_test/test.js:3:19)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Module.require (module.js:466:17)
at require (internal/module.js:20:19)
at /usr/local/lib/node_modules/mocha/lib/mocha.js:220:27
at Array.forEach (native)
at Mocha.loadFiles (/usr/local/lib/node_modules/mocha/lib/mocha.js:217:14)
at Mocha.run (/usr/local/lib/node_modules/mocha/lib/mocha.js:485:10)
at Object. (/usr/local/lib/node_modules/mocha/bin/_mocha:405:18)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:159:18)
at node.js:444:3
Your code is a mix between ES5 and ES6 syntax.
I think that the problem come from this portion of code :
var React = require('react');
var {shalow} = require('enzyme');
var {SearchBox} = require('../static/js/functions');
If you wanna use ES5 syntax :
var React = require('react');
var shalow = require('enzyme').shalow; // notice how we access object property `.objectProperty`
var SearchBox = require('../static/js/functions');
If you wanna use ES6 syntax :
import React from 'react';
import {shalow} form 'enzyme'; // notice how we access object property `{objectProperty}`
import SearchBox form '../static/js/functions';
also make sure at the end of your function.js file, you export the component with :
module.exports = SearchBox; // ES5 syntax
export default SearchBox; // ES6 syntax
You need to update Node (mocha is depending on node.js) version (to support es6 modules) or export your component using requireJS - module.exports ... + You should check what parts of es6 your node version supports, because code passed to mocha is not "babelized" :)