babel-preset-es2015 is installed, and is OK with es6 feature just like below let a = 2;.
But can not work with es6 modules feature import fs from 'fs' as following:
$ babel-node --presets es2015
> let a = 2;
'use strict'
> a
2
> import fs from 'fs';
SyntaxError: repl: Modules aren't supported in the REPL
import fs from 'fs';
at File.buildCodeFrameError (/usr/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:407:15)
at NodePath.buildCodeFrameError (/usr/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/path/index.js:149:26)
at PluginPass.ModuleDeclaration (/usr/lib/node_modules/babel-cli/lib/_babel-node.js:78:20)
at newFn (/usr/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/visitors.js:262:19)
at NodePath._call (/usr/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/path/context.js:63:18)
at NodePath.call (/usr/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/path/context.js:47:17)
at NodePath.visit (/usr/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/path/context.js:93:12)
at TraversalContext.visitQueue (/usr/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/context.js:152:16)
at TraversalContext.visitMultiple (/usr/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/context.js:110:17)
at TraversalContext.visit (/usr/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/context.js:182:19)
So what's wrong?
Thanks!
The error message is exactly what it says. You cannot use ES6 module syntax in the REPL, it is unsupported. You can create a small adapter that imports as ES6 and exports as CommonJS:
# es6-to-common.js
import MyThing from './somewhere';
module.exports = MyThing;
Now inside your usual babel-node prompt:
> MyThing = require('./es6-to-common')
Got it from the official doc:http://babeljs.io/docs/usage/cli/
ES6-style module-loading may not function as expected
Due to technical limitations ES6-style module-loading is not fully supported in a babel-node REPL.
Related
I got below error, try adding signature to my angular 6 project
node module : - angular-signature-pad
error: - ERROR in src/app/app.module.ts(5,41): error TS2307: Cannot find module 'angular-signature-pad'.
Things to check?
1) Did you install the package ?
npm install angular-signature-pad --save
2) Import the package in app module.
import { AngularSignaturePadModule } from 'angular-signature-pad';
#NgModule({
imports: [
...
AngularSignaturePadModule.forRoot()
]
...
})
export class AppModule { }
Maybe possibility, It may not be working in angular 4 plus.
https://github.com/BioPhoton/angular-signature-pad/issues/2
try updating node.js to version 16+
or
update angular cli
ng update #angular/cli #angular/core
Below is a basic example of gcloud background function with a dependency in it. On using uuid package it throws up an error although package.json has uuid
On deploying following erros is received.
gcloud beta functions deploy helloPubSub --trigger-resource my-topic --trigger-event google.pubsub.topic.publish
ERROR: (gcloud.beta.functions.deploy) OperationError: code=3, message=Function load error: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'uuid'
index.js
const uuid = require('uuid');
exports.helloPubSub = (event, callback) => {
const pubsubMessage = event.data;
const eventName = pubsubMessage.data ? Buffer.from(pubsubMessage.data, 'base64').toString() : 'World';
console.log(eventName,uuid.v4());
callback();
};
package.json
"dependencies": {
"uuid": "^3.2.1"
},
There was an issue in my .gcloudignore
Below change did make it work!
From
node_modules/
to
node_modules
Trying to run eslint with gulp and getting this error. What have I missed? Here's my gulpfile.bable.js file.
import gulp from 'gulp';
import eslint from 'eslint';
const jsFiles = ['*.js', 'src/**/*.js'];
gulp.task('lint', () => {
gulp.src(jsFiles)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
Here's the full error:
C:\Users\promer\projects\library>gulp lint
[14:50:35] Requiring external module babel-register
[14:50:35] Using gulpfile ~\projects\library\gulpfile.babel.js
[14:50:35] Starting 'lint'...
[14:50:35] 'lint' errored after 10 ms
[14:50:35] TypeError: (0 , _eslint2.default) is not a function
at Gulp.<anonymous> (C:/Users/promer/projects/library/gulpfile.babel.js:8:11)
at module.exports (C:\Users\promer\projects\library\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (C:\Users\promer\projects\library\node_modules\orchestrator\index.js:273:3)
at Gulp.Orchestrator._runStep (C:\Users\promer\projects\library\node_modules\orchestrator\index.js:214:10)
at Gulp.Orchestrator.start (C:\Users\promer\projects\library\node_modules\orchestrator\index.js:134:8)
at C:\Users\promer\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:394:7)
It was a simple mistake. I almost deleted the question, but I figured someone else might make the same mistake I did. While I have gulp-eslint installed I was actually loading regular eslint into my gulp file. The fix is to change this line
import eslint from 'eslint'
to
import eslint from 'gulp-eslint'
I have installed:
$ npm install protractor-jasmine2-html-reporter --save-dev
for reporter
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
exports.config = {
// ...
onPrepare: function() {
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
savePath: 'target/screenshots'
})
);
}
}
and defined the path where the reporter is installed
var Jasmine2HtmlReporter =
require('../../build/node_modules/protractor-jasmine2-html-reporter');
Now i get this Error:
configParser - ReferenceError: jasmine is not defined
How should i define jasmine?
For info: i have a test execution task defined in a gulp file and i run the task using webstorm.
I have seen ReferenceError: jasmine is not defined in other reporters(jasmine-repoters) when there is a version mismatch.
Can you upgrade your protractor & reporter versions. Also make sure you have Jasmine2 as the framework in your config file
The below combination has been tested and is working fine
Protractor - 4.0.10
protractor-jasmine2-html-reporter - 0.0.7
Jasmine ~2
I have a module module-A which has the following in index.js
import SomeModule from './lib/some-module'
import AnotherModule from './lib/another-module'
module.exports ={
SomeModule: SomeModule,
AnotherModule: AnotherModule
}
I then use this module-A from another module-B:
import SomeModule from `module-A`
I now want to build module-B for the browser, so I use browserify from the module-B cwd: [I am using babel 6.0]
browserify index.js -t [ babelify --presets [ es2015 ] ]
This throws an error as
import SomeModule from './lib/some-module'
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
Is there anyway I can export modules using es6 export and import syntax and yet build properly for the browser.