所以我想做:
if (process.env.NODE_ENV === 'production') {
import StatsPlugin from 'webpack-stats-plugin';
}
Run Code Online (Sandbox Code Playgroud)
但是eslint说:
Parsing error: 'import' and 'export' may only appear at the top level
Run Code Online (Sandbox Code Playgroud)
我正在使用babel-eslint解析器.
这是否意味着我无法有条件地加载模块?
此示例不进行类型检查:
type Subset1 = "one" | "two";
type Subset2 = "three" | "four";
type All = Subset1 | Subset2;
type Other = {
"one": number,
"two": string,
"three": boolean,
"four": object,
};
type Extra<V> = V extends Subset1 ? string : undefined;
function doOtherThing(stuff: string){}
function doThing<V extends All>(value: V, params: Other[V], extra: Extra<V>) { }
function doSubset1Thing<V extends Subset1>(value: V, params: Other[V], extra: string) {
doThing(value, params, extra);
doOtherThing(extra);
}
function doSubset2Thing<V extends Subset2>(value: V, params: Other[V]) {
doThing(value, …Run Code Online (Sandbox Code Playgroud) 我是nodeJS和节点扩展的新手.我正在为节点js编写一个本机扩展,它将在虚函数OnEvent(param1,param2,param3)上接收回调.代码如下:
bool MyExt::OnEvent(int eventType, string param1, string param2)
{
printf("MyExt:: onevent___ \n");
{
//// Crashes here, but if I use Locker, it get stuck!!!!!!
//Locker l;
Local<Value> argv[3] = {
Local<Value>::New(Integer::New(1)),
Local<Value>::New(String::New("parameter 1")),
Local<String>::New(String::New("parameter 2"))
};
TryCatch try_catch;
//// I need to call this
m_EventCallback->Call(Context::GetCurrent()->Global(), 3, argv);
if (try_catch.HasCaught()){
printf("Callback is Exception() \n");
}
printf("Callback is IsCallable() \n");
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
我需要使用m_EventCallback将此回调参数转发到服务器脚本.函数bool OnEvent是从另一个线程调用的.
我尝试使用uv_async_send但无法成功.
任何帮助或指导将不胜感激.
首先......我有下一个gulp任务:
gulp.task('js', function() {
browserify('./src/js/main.js')
.bundle()
.on('error', onError)
.pipe( source('main.js') )
.pipe( gulp.dest(path.build.js) );
});
Run Code Online (Sandbox Code Playgroud)
和package.json:
{
"browserify": {
"transform": [
["babelify", { "presets": ["es2015"] }],
"debowerify"
]
},
}
Run Code Online (Sandbox Code Playgroud)
我在main.js中导入Backbone(或者只是下划线......没关系)
import Backbone from 'backbone';
Run Code Online (Sandbox Code Playgroud)
在控制台我得到错误
未捕获的TypeError:无法读取未定义的属性"_"
我检查了代码,发现在库的开头是下划线源root是未定义的
// Establish the root object, `window` in the browser, or `exports` on the server.
var root = this;
// Save the previous value of the `_` variable.
var previousUnderscore = root._;
Run Code Online (Sandbox Code Playgroud)
我认为问题在于debowerify或babelfy是将代码包装在某个函数中.但是如果我使用没有debowerify的节点模块,一切正常.但我想用凉亭.
那么如何解决这个问题呢?
我有一个vue组件
vue-compoennt(vue-loader)
<template>
<p>This is a template</p>
</template>
<script>
require('main.js')
huha()
</script>
Run Code Online (Sandbox Code Playgroud)
我有
main.js
var huha = function(){
alert("this is huha");
};
alert("this is simple alert");
Run Code Online (Sandbox Code Playgroud)
在这里,我得到了"简单警报",但在评估huha()时,它显示了参考错误.有人可以帮我理解为什么会这样吗?
编辑
我试图使用testimonial.js如下,我得到参考错误.
<template>
<p>This is a template</p>
<div id="testimonial-slider"></div>
</template>
<script>
require('testimonial/testimonial.js')
require('testimonial/testimonial.css')
var testimonial = new Testimonial('#testimonial-slider');
</script>
<style>
p{
color: red;
}
</style>
Run Code Online (Sandbox Code Playgroud)
它给出了"参考错误:证词没有定义"
当我运行webpack时,我收到此错误:
ERROR in Entry module not found: Error: Cannot resolve module 'game'
in /Users/frederikcreemers/dev/dark_chess
Run Code Online (Sandbox Code Playgroud)
(为了清晰起见,添加了换行符.)
但我确信game.js存在.
这是我的webpack.config.js样子:
module.exports = {
entry: "game.js",
output: {
path: __dirname + "build",
filename: "index.js"
},
module: {
loaders: [
{ test: /\.css$/, loader: "style!css" },
{ test: /\.jsx?$/, loader: "babel?presets[]=es2015", exclude: /(node_modules|bower_components)/}
]
}
};
Run Code Online (Sandbox Code Playgroud)
我不确定如何进一步调查此问题.
我正在尝试使用react-router我的早午餐/巴贝尔设置.在我的app.js中,我有:
import React from "react"
import ReactDOM from "react-dom"
import { Router, Route, Link } from "react-router"
Run Code Online (Sandbox Code Playgroud)
然而,这给了我:
未捕获错误:无法从"react-router/Router"找到模块"history/lib/createHashHistory"
在查看参考线时,我看到:
var _historyLibCreateHashHistory = require('history/lib/createHashHistory');
Run Code Online (Sandbox Code Playgroud)
当检查app.js通过早午餐产生的那个时,我看到:
require.register('history/createBrowserHistory', function(exports,req,module) {
...
});
Run Code Online (Sandbox Code Playgroud)
我如何解决此问题以便createBrowserHistory正确导入?
首先,我想说的是,我真的不知道如何解释我为获得标题中提到的错误所做的事情 ( uncaught TypeError: Illegal constructor)。我正在使用 gulpfile 将我的 Ecmascript 6 编译为纯 Javascript。我的 gulpfile 看起来像这样:
var gulp = require('gulp');
var concat = require('gulp-concat');
var babel = require('gulp-babel');
gulp.task('compile', function () {
return gulp.src(['resources/assets/js/*.js', 'resources/assets/js/components/*.js'])
.pipe(babel({
presets: ['es2015']
}).on('error', logError))
.pipe(concat('bundle.js'))
.pipe(gulp.dest('public/js'));
});
gulp.task('watch', function () {
gulp.watch('resources/assets/js/**/*', ['compile']);
})
gulp.task('default', ['watch']);
function logError(err) {
console.log(err);
}
Run Code Online (Sandbox Code Playgroud)
我有一个文件系统,在用 Babel 编译后,所有文件都连接到一个文件 (bundle.js)。
在浏览器控制台(Chrome 或 Firefox)中,错误出现并位于下一行:
var _this = _possibleConstructorReturn(this, (Dropdown.__proto__ || Object.getPrototypeOf(Dropdown)).call(this, element));
Run Code Online (Sandbox Code Playgroud)
这是这个的非编译代码:
class Dropdown extends Node {
constructor(element) {
super(element); …Run Code Online (Sandbox Code Playgroud) 我正在使用NightWatch进行e2e测试,并希望转向ES6编写测试的方式.我能够用Babel做到这一点并且工作正常,但我想使用打字稿.我用TypeScript找不到很多关于NightWatch的文档.找到一些github存储库:
但这些不包含任何有关打字稿的详细文档.
任何帮助,将不胜感激!
我有一个index.js文件,内容如下:
import aReducer from './ducks/a';
import bReducer from './ducks/b';
import * as aSelectors from './ducks/a';
import * as bSelectors from './ducks/b';
console.log(aReducer) //function i expect
console.log(aSelectors) //object with keys to selectors i expect
export { aReducer, bReducer, ...aSelectors, ...bSelectors };
Run Code Online (Sandbox Code Playgroud)
如果我console.log在这个文件中,我会看到化简器是我期望的函数,而选择器别名是带有我期望的选择器键的对象。减速器是鸭子文件的默认导出,选择器是来自同一相应文件的导出。
但是,当我尝试使用另一个文件导入此模块时,我只能导入两个减速器。这两个选择器未定义。我认为解构会将每个键添加到我的导出对象中。我究竟做错了什么?
other_file1.js
import { aReducer, bReducer } from 'my-module'; //works!
Run Code Online (Sandbox Code Playgroud)
other_file2.js
import { someSelectorThatWasInMyaSelectorsObject } from 'my-module'; //does NOT work!
Run Code Online (Sandbox Code Playgroud) babeljs ×7
javascript ×4
webpack ×3
ecmascript-6 ×2
gulp ×2
typescript ×2
browserify ×1
brunch ×1
callback ×1
e2e-testing ×1
es6-modules ×1
eslint ×1
export ×1
import ×1
node.js ×1
react-router ×1
vue.js ×1