Dart Dev Compiler: Error: Cannot find module 'dart_sdk' - dart

I am searching about Dart to Javascript and trying to do some node play but got stuck on this error:
internal/modules/cjs/loader.js:584
throw err;
^
Error: Cannot find module 'dart_sdk'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (C:\Users\shina\Desenvolvimento\dart_projects\tests_dart\example\main.js:2:18)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
What I did:
I have a main.dart and run the following command on it:
dartdevc --modules node -o main.js .\main.dart
After that i just run: node main.js.
This is my main.dart file:
main() {
print("Hello World!");
}
This is the main.js file generated by dartdevc:
'use strict';
const dart_sdk = require('dart_sdk');
const core = dart_sdk.core;
const dart = dart_sdk.dart;
const dartx = dart_sdk.dartx;
const main = Object.create(dart.library);
main.main = function() {
core.print("Hello World!");
};
dart.trackLibraries("minimain", {
"main.dart": main
}, {
}, null);
// Exports:
exports.minimain = main;
//# sourceMappingURL=minimain.js.map

Related

How can I use Faker library on Artillery's Docker Image?

So my dilemma is I want to run my script, which has a processor function that uses Faker library, on Gitlab Pipeline. The problem is the Artillery does not have the Faker library. I tried installing Faker inside the docker container as an experiment, but my script is still not working.
Here's the code of my processor.js file
const Faker = require("faker");
function generateLinkData(requestParams, ctx, ee, next) {
let firstname = Faker.name.firstName();
let lastname = Faker.name.lastName();
ctx.vars["amount"] = Faker.finance.amount(5, 1000000, 2);
ctx.vars["reference"] = Faker.commerce.price(100000, 200000, 0);
ctx.vars["description"] = Faker.commerce.productDescription();
ctx.vars["email_link"] = Faker.internet.email(firstname, lastname,'mailinator.com');
ctx.vars["contact_first_name"] = firstname;
ctx.vars["contact_last_name"] = lastname;
return next();
}
module.exports = {
generateLinkData,
};
And here's the error:
node:internal/modules/cjs/loader:933
const err = new Error(message);
^
Error: Cannot find module 'faker'
Require stack:
- /builds/trial304/artillery-load-test/tests/performance/processor.js
- /home/node/artillery/core/lib/runner.js
- /home/node/artillery/lib/util.js
- /home/node/artillery/lib/console-reporter.js
- /home/node/artillery/lib/artillery-global.js
- /home/node/artillery/bin/run
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/builds/trial304/artillery-load-test/tests/performance/processor.js:2:15)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/builds/trial304/artillery-load-test/tests/performance/processor.js',
'/home/node/artillery/core/lib/runner.js',
'/home/node/artillery/lib/util.js',
'/home/node/artillery/lib/console-reporter.js',
'/home/node/artillery/lib/artillery-global.js',
'/home/node/artillery/bin/run'
]
}
This is the command I run inside the docker container to install faker:
npm install #faker-js/faker --save-dev
The processor won't run and causes error since it needs the Faker library and it seems the Faker library is not being recognized (??). I hope anyone could help me with this. Thank you!

Using Electron 10 with Requirejs in renderer returns an error

I have been using requirejs (latest) with Electron 9, but since Electron 10 when including it in the renderer script I see the following error:
node_modules/requirejs/bin/r.js:1
(function (exports, require, module, __filename, __dirname, process, global, Buffer) { return function (exports, require, module, __filename, __dirname) { #!/usr/bin/env node
^
SyntaxError: Invalid or unexpected token
at new Script (vm.js:88:7)
at createScript (vm.js:261:10)
at Object.runInThisContext (vm.js:309:10)
at wrapSafe (internal/modules/cjs/loader.js:1047:15)
at Module._compile (internal/modules/cjs/loader.js:1108:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1173:10)
at Module.load (internal/modules/cjs/loader.js:992:32)
at Module._load (internal/modules/cjs/loader.js:885:14)
at Function.f._load (electron/js2c/asar_bundle.js:5:12694)
at Module.require (internal/modules/cjs/loader.js:1032:19)
To reproduce:
in main.js
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration:true
}
})
//and load the index.html of the app.
mainWindow.loadFile('index.html')
in index.html:
<script src="./renderer.js"></script>
in renderer.js:
var r = require('requirejs');

solcover fail to generate test coverage with my simple add contract

I want to use solcover to generate test coverage of my contract.
https://github.com/JoinColony/solcover
I test it with the simple one:
contract Add {
function Add() {
}
function sum(uint x, uint y) returns (uint) {
return (x+y);
}
}
And here is my test code:
contract('Add', function(accounts) {
it("should return 5 when add 2 and 3", function() {
var add = Add.deployed();
return add.sum.call(2,3).then(function(res){
assert.equal(res.valueOf(), 5, "add result is 5");
});
});
});
But there are some errs when compile it.
Add.sol:2:1: Warning: Source file does not specify required compiler version!Consider adding "pragma solidity ^0.4.6
contract Add {
^
Spanning multiple lines.
Compilation failed. See above.
fs.js:549
Then i add compile version like this:
pragma solidity ^0.4.6;
contract Add {
function Add() {
}
function sum(uint x, uint y) returns (uint) {
return (x+y);
}
}
And now it pass the compile. But this time I got the error:
cp: no such file or directory: ./../originalContracts/Migrations.sol
rm: no such file or directory: ./allFiredEvents
Compiling Add.sol...
Contract: Add
✓ should return 5 when add 2 and 3
1 passing (15s)
fs.js:549
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: ENOENT: no such file or directory, open './allFiredEvents'
at Error (native)
at Object.fs.openSync (fs.js:549:18)
at Object.fs.readFileSync (fs.js:397:15)
at Object.<anonymous> (/Users/maiffany/graduate/mytest/solcover/runCoveredTests.js:60:13)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
And in the runCoveredTests.js I found this:
55:shell.cp("./../originalContracts/Migrations.sol",./../contracts/Migrations.sol");
56:
57:shell.rm('./allFiredEvents'); //Delete previous results
58:shell.exec('truffle test --network coverage');
59:
60:events = fs.readFileSync('./allFiredEvents').toString().split('\n')
I guess maybe it is this command that generate file "allFiredEvents". So i try this in my command line:
truffle test --network coverage
Compiling Add.sol...
Contract: Add
✓ should return 5 when add 2 and 3
1 passing (24s)
But i still can't find the file "allFiredEvents".
So where did i get wrong?

Gulp wiredep error on jquery-ui

I use wiredep to get all vendor components and put them in a temporary folder, but when I add jquery-ui, wiredep fails.
gulpfile.js
gulp.task('build:vendor', ['cleanVendor'], function () {
var files = require('wiredep')();
var stream = gulp.src(files.js);
// ...other code here
});
the error output:
C:\Dev\node_modules\wiredep\wiredep.js:30
('on-error', opts.onError || function(err) { throw new Error(err); })
^
Error: Error: jquery-ui is not installed. Try running `bower install` or remove
the component from your bower.json file.
at C:\Dev\node_modules\wiredep\wiredep.js:30:56
at C:\Dev\node_modules\wiredep\lib\detect-dependencis.js:149:29
at forOwn (C:\Dev\node_modules\wiredep\node_modules\lodash\dist\lodash.js:2106:15)
at Function.forEach (C:\Dev\node_modules\wiredep\node_modules\lodash\dist\lodash.js:3303:9)
at detectDependencies (C:\Dev\node_modules\wiredep\lib\detect-dependencies.js:34:7)
at wiredep (C:\Dev\node_modules\wiredep\wiredep.js:70:39)
at Object.<anonymous> (C:\Dev\gulp\prep.js:16:33)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
bower.json:
{
"name": "project",
"version": "0.0.1",
"dependencies": {
"angular-messages": "^1.4.2",
"angular-aria": "^1.4.2",
"jquery": "^1.11.3",
"angular": "^1.4.2",
"jquery-ui": "1.11.4"
}
}
I tried adding an override to the bower.json file, but the result was the same.
The strange thing is that this works in node shell.
other possibly useful information:
Visual Studio 2015
NodeJS version: 0.12.2
gulp version: 3.9.0
wiredep versions: 2.2.2, 3.0.0-beta (tried both)
Found my mistake,
gulp.task('build:vendor', ['cleanVendor'], function () {
var files = require('wiredep')();
var stream = gulp.src(files.js);
// ...other code here
});
should be:
gulp.task('build:vendor', ['cleanVendor'], function () {
var files = require('wiredep')({ directory: 'bowerDirectoryHere'});
var stream = gulp.src(files.js);
// ...other code here
});
the default (I'm not sure where it is pulled from) was one level too high. The strange part is that it only fails on jquery-ui and not angular or others.

'Trying to open unclosed connection' error' using Mongoose and embedded documents

I'm getting a connection related error when defining a static query that filters an embedded document field.
I've tried to separate the embedded document in a separate schema file but didn't resolve the issue. Any ideas?
Error follows:
C:\development_GIT\myproject\app\models\mymodel.js:40
this.find({ text.lang_code: langCode }).sort('text.name').exec(callback);
^
Error: Trying to open unclosed connection.
at NativeConnection.Connection.open (C:\development_GIT\myproject\node_
modules\mongoose\lib\connection.js:205:15)
at Mongoose.connect (C:\development_GIT\myproject\node_modules\mongoose
\lib\index.js:156:15)
at Object.<anonymous> (C:\development_GIT\myproject\server.js:13:10)
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 repl:1:1
The error is launched when using the filter { text.lang_code: langCode }
option in the following model. If I don't use the embedded document and try to filter for exampe { _id: langCode } it does not throw errors.
//MyModel.js located at ./app/models
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var MyModelSchema = new Schema({
name: { type: String, trim: true },
text: [{ name: String, lang_code: String }]
});
MyModelSchema .static({
findByLangCode : function(langCode, callback) {
this.find({ text.lang_code: langCode }).sort('text.name').exec(callback);
}
});
mongoose.model('MyModel', CategorySchema);
The first lines of my main file server.js are:
//server.js
var express = require('express');
var env = process.env.NODE_ENV || 'development';
var config = require('./config/config')[env];
var mongoose = require('mongoose');
var fs = require('fs');
require('express-namespace');
mongoose.connect(config.db);
// Bootstrap models
fs.readdirSync(__dirname + '/app/models').forEach(function (file) {
if (~file.indexOf('.js')) require(__dirname + '/app/models/' + file)
});
Solution was building the query in a different way. It seems that subdocuments can not be used inside find().
Before: (not working)
this.find({ text.lang_code: langCode }).sort('text.name').exec(callback);
After (working)
this.find().where('text.lang_code').equals(langCode).sort('text.name').exec(callback);
Im using this all the time and it works fine for me.
this.find({ 'text.lang_code': langCode }).sort('text.name').exec(callback);
MongoDb can only handle one lvl of objects, but if you give it a string like you are doing in the .where function, mongodb will do magic and match it to subdocuments :)

Resources