I just made an script to compile our scss when we save the file with gulp but I execute "gulp sass" I receive the next error:
gulp.task('sass', function () => {
^
SyntaxError: Invalid or unexpected token
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at requireOrImport (C:\Users\smartinc\AppData\Roaming\npm\node_modules\gulp-cli\lib\shared\require-or-import.js:19:11)
at execute (C:\Users\smartinc\AppData\Roaming\npm\node_modules\gulp-cli\lib\versioned\^4.0.0\index.js:37:3)
at Liftoff.handleArguments (C:\Users\smartinc\AppData\Roaming\npm\node_modules\gulp-cli\index.js:211:24)
This is the code:
const gulp = require('gulp');
const sass = require('gulp-sass');
sass.compiler = require('node-sass');
// Creates the task that will compile our scss
gulp.task('sass', () => {
// TODO: Must be a way to call a variable with scss route
return gulp.src('./cartridges/peru/cartridge/client/default/scss/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./cartridges/peru/cartridge/static/default/css'));
});
The thing is that it works just fine in my computer but it doesnt work in my partner's computer.
I have no clue of what could be happening.
Any help?
Related
I want to use p-queue npm nodejs. But it get me error. Help me why it was and how to fix it? Here my code:
const shell = require("shelljs");
const async = require("async");
const fs = require("fs");
const path = require("path");
const { default: PQueue } = require("p-queue");
const queue = new PQueue({ concurrency: 1 });
And this error:
internal/modules/cjs/loader.js:1080
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module:
C:\Users\Feruz\Desktop\codeMaster\judge\node_modules\p-queue\dist\index.js
require() of ES modules is not supported. require() of
C:\Users\Feruz\Desktop\codeMaster\judge\node_modules\p-queue\dist\index.js
from C:\Users\Feruz\Desktop\codeMaster\judge\judge.js is an ES module
file as it is a .js file whose nearest parent package.json contains
"type": "module" which defines all .js files in that package scope as
ES modules. Instead rename index.js to end in .cjs, change the
requiring code to use import(), or remove "type": "module" from
C:\Users\Feruz\Desktop\codeMaster\judge\node_modules\p-queue\package.json.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\Users\Feruz\Desktop\codeMaster\judge\judge.js:5:29)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14) { code: 'ERR_REQUIRE_ESM' } [nodemon] app crashed - waiting for file
changes before starting...
Is it possible to compile the main process of electron main.js with some tool? I am using nexe to compile the main process main.js but it doesn't work.Is there a way to do that?
I am using https://github.com/electron/electron-quick-start
Then I use nexe main.js to generate a compilation.
Then I modify package.json by changing the value of main.js to main.exe.
Finally npm start and I get an error message:
MZ´┐¢
SyntaxError: Invalid or unexpected token
at Module._compile (internal/modules/cjs/loader.js:895:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1004:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module._load (electron/js2c/asar.js:769:28)
at loadApplicationPackage (C:\Users\Onimac\AppData\Roaming\npm\node_modules\electron\dist\resources\default_app.asar\main.js:109:16)
at Object.<anonymous> (C:\Users\Onimac\AppData\Roaming\npm\node_modules\electron\dist\resources\default_app.asar\main.js:155:9)
at Module._compile (internal/modules/cjs/loader.js:967:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1004:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
Minified main.js code:
const {app, BrowserWindow} = require('electron');
function createWindow () {
const mainWindow = new BrowserWindow({
width: 800,
height: 600
})
mainWindow.loadFile('index.html')
}
app.whenReady().then(() => {
createWindow()
})
I have a problem regarding my task automation. I am using gulpJS and my css used is gulp-sass. I tried to learn this from a youtube video I found online -> https://www.youtube.com/watch?v=LYbt50dhTko and my main problem is, I tried to automate my css so that I won't have a hard time compiling both my css and sass files but I always get an error that says:
assert.js:339
throw err;
^
AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask]
(C:\Users\Applicant\Documents\responsive_screen\node_modules\undertaker\lib\set-task.js:10:3)
at Gulp.task
(C:\Users\Applicant\Documents\responsive_screen\node_modules\undertaker\lib\task.js:13:8)
at Object.<anonymous> (C:\Users\Applicant\Documents\responsive_screen\gulpfile.js:22:6)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
This is my first time coding in gulp js and I really want to learn this one. I will post my source code below this paragraph:
var gulp = require('gulp');
var sass = require('gulp-sass');
var uglifycss = require('gulp-uglifycss');
var watch = require('gulp-watch');
gulp.task('css', function(){
gulp.src('./css/*.css')
.pipe(uglifycss({
"maxLineLen": 80,
"uglyComments" : true
}))
.pipe(gulp.dest('./dist/'));
});
gulp.task('sass', function () {
return gulp.src('./sass/*.scss')
.pipe(sass.sync().on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
gulp.task('run', ['sass', 'css']);
gulp.task('watch', function(){
gulp.watch('./sass/*.scss', ['sass']);
gulp.watch('./css/*.css', ['css']);
});
gulp.task('default', ['run', 'watch']);
Can someone share solutions or ideas to this problem? It would be very much appreciated!
I have a mocha test file (test/test.js) that starts like this, using ES6 module syntax:
import {promises as fs} from 'fs'
import stepToD3 from '../src/StepToD3'
import assert from "assert"
In addition, I have a babel.config.js file in the root of my project:
module.exports = {
presets: [
"#vue/app",
"#babel/preset-env"
]
}
I then want to test this using Mocha, transpiled through babel. I do so using mocha --require #babel/register test/test.js. However, somewhere during the execution, this fails with the following error:
/home/michael/Programming/cola-step/node_modules/#babel/runtime-corejs2/helpers/esm/asyncToGenerator.js:1
(function (exports, require, module, __filename, __dirname) { import _Promise from "../../core-js/promise";
^^^^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:84:7)
at createScript (vm.js:264:10)
at Object.runInThisContext (vm.js:312:10)
at Module._compile (internal/modules/cjs/loader.js:684:28)
at Module._compile (/home/michael/Programming/cola-step/node_modules/pirates/lib/index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Object.newLoader [as .js] (/home/michael/Programming/cola-step/node_modules/pirates/lib/index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Module.require (internal/modules/cjs/loader.js:657:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/home/michael/Programming/cola-step/test/test.js:7:49)
at Module._compile (internal/modules/cjs/loader.js:721:30)
at Module._compile (/home/michael/Programming/cola-step/node_modules/pirates/lib/index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Object.newLoader [as .js] (/home/michael/Programming/cola-step/node_modules/pirates/lib/index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Module.require (internal/modules/cjs/loader.js:657:17)
at require (internal/modules/cjs/helpers.js:22:18)
at /usr/lib/node_modules/mocha/lib/mocha.js:231:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/usr/lib/node_modules/mocha/lib/mocha.js:228:14)
at Mocha.run (/usr/lib/node_modules/mocha/lib/mocha.js:536:10)
at Object.<anonymous> (/usr/lib/node_modules/mocha/bin/_mocha:573:18)
at Module._compile (internal/modules/cjs/loader.js:721:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
at executeUserCode (internal/bootstrap/node.js:342:17)
at startExecution (internal/bootstrap/node.js:276:5)
at startup (internal/bootstrap/node.js:227:5)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
Why is this failing to understand the ES6 import syntax if I'm using Babel? What is going wrong here?
In this case, I was running my tests with mocha on NodeJS, but my babel.config.js was set up to produce code for the browser. To fix this, I had to create two different babel settings, and then export the right NODE_ENV value before running the appropriate command (e.g. NODE_ENV=test mocha --require #babel/register for tests, and NODE_ENV=production for my webpack production build).
This is my new babel.config.js:
module.exports = {
'env': {
'production': {
'presets': [
[
'#vue/app',
{
// "modules": false,
'targets': ['ie >= 9']
},
'#babel/env'
]
],
'comments': false
},
'test': {
'presets': [
[
'#babel/env',
{'targets': {'node': 'current'}}
]
]
}
}
}
I have a working Node application and I'm trying to add Mocha tests, but getting some odd import errors.
This is my file structure:
package.json
index.js
src/
chart.js
highcharts-options.js
test/
test_chart.js
This is what my chart.js file looks like:
var chartOptions = require('./highcharts-options');
var analyseChart = {
doSomething: function() { ... }
};
module.exports = analyseChart;
And this is what highcharts-options.js looks like:
var HighCharts = require('highcharts-browserify');
Highcharts.theme = { ... };
Currently I import everything from /src into a single index.js file, then bundle it with browserify, which works just fine, no errors in the application.
Now I want to start writing Mocha tests for the functions in /src.
This is my first stub in test_chart.js:
var chart = require('../src/chart');
chart.doSomething();
But when I run mocha, I get the following error:
Users/.../js/src/highcharts-options.js:11
Highcharts.theme = {
^
ReferenceError: Highcharts is not defined
at Object.<anonymous> (/Users/.../js/src/highcharts-options.js:11:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/.../js/src/chart.js:7:20)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/.../js/test/test_chart.js:1:75)
How can I fix this import error for Mocha?
var HighCharts = require('highcharts-browserify');
Highcharts.theme = { ... };
You have a spelling error.
High[cC]harts
How did you not notice this yourself even when you were told exactly what was wrong?
Some errors are so common that we ultimately stop trusting them, and start looking for other faults in our code without even investigating it.
This is especially true for the "someVar is undefined" error in javascript.
Takeaway:
Sometimes you just got to trust your error messages.