Object is not a function (evaluating 'function()') in react-native - react-native

I recently installed a package named 'trilat' via npm.
And I saw a warning after the installation of this package.
( which said I skipped optional dependency: fsevents#1.1.3 (node_modules/fsevents)
and unsupported platform for fsevents#1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
I did not really care this err since npm installed the whole package.
But after I wrote a code using this package, I see an error message what looks like the question title.
It says that the Object is not a function (evaluating 'abstractMatrix()') and abstractMatrix is a function declared in the package.
I don't see this error occured due to the fsevent(which npm says it is supported in darwin).
here is the partial code related to abstractMatrix()
function abstractMatrix(superCtor) {
if (superCtor === undefined) superCtor = Object;
/**
* Real matrix
* #class Matrix
* #param {number|Array|Matrix} nRows - Number of rows of the new matrix,
* 2D array containing the data or Matrix instance to clone
* #param {number} [nColumns] - Number of columns of the new matrix
*/
class Matrix extends superCtor {
static get [Symbol.species]() {
return this;
}
.
.
.
and so on
what am i doing wrong?

If you want to use this in the browser without browserify/webpack/etc,
include the dist.js file, which exposes the symbol trilat as a global
function.
Last words from the author of the project you are including from this repo here.
So, include the dist.js file from that project into your project src files, maybe even place it in your utils directory & import it in the files you want to use and use from there.
The project uses webpack/browserify and other stuff which I doubt are included in your build.

Related

why should I declare the command again in `activationEvents` filed of package.json?

as the sample says
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
so I register the command at the activationEvents again?
kind of counterintuitive.
It became unnecessary to put your commands into the activationEvents part of your package.json with vscode v1.74 Stable. From v1.74 Release Notes: implicit activation events:
Implicit activation events for declared extension contributions
This milestone we removed the requirement to explicitly list
activation events if your extension declares certain extension
contributions in its package.json.
Previously, if an extension declared that it contributed a command
mycommand in its package.json file, it also needed to list the
corresponding onCommand:mycommand activation event in the
activationEvents field of package.json for the command to
successfully execute. This was tedious and error-prone and could lead
to large package.json files.
VS Code will now automatically populate activation events for the
following extension contribution points:
onCommand
onAuthenticationRequest
onLanguage
onCustomEditor
onView
Extension authors can now safely remove these inferred activation
events from your extensions. If you do so, update your VS Code engine
requirement to ensure that your extension is not treated as compatible
with earlier versions of VS Code:
"engines": {
"vscode": "^1.74.0"
}, ```

aurelia-cli error when using buffer.js - global undefined

Created a new project using the aurelia-cli - SystemJS bundler option.
installed htmlparser2 module from npm which has buffer.js as a dependency.
getting the following error when attempting to import htmlparser2:
bluebird.core.js:3434 Error: global is not defined
Evaluating http://localhost:9000/buffer/index
upon inspecting vendor-bundle -> this is the line that creates the error:
Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
? global.TYPED_ARRAY_SUPPORT
: typedArraySupport()
found a similar issue with angualar-cli where the solution was to manually turn on node global
Node global is turned off. It works fine if I manually turn it on again.
The question is how to do this using the aurelia-cli? Any suggestions?
larger code snippet from vendor-bundle
define('buffer/index',['require','exports','module','base64-js','ieee754','isarray'],function (require, exports, module) {/*!
* The buffer module from node.js, for the browser.
*
* #author Feross Aboukhadijeh <feross#feross.org> <http://feross.org>
* #license MIT
*/
/* eslint-disable no-proto */
'use strict'
var base64 = require('base64-js')
var ieee754 = require('ieee754')
var isArray = require('isarray')
exports.Buffer = Buffer
exports.SlowBuffer = SlowBuffer
exports.INSPECT_MAX_BYTES = 50
/**
* If `Buffer.TYPED_ARRAY_SUPPORT`:
* === true Use Uint8Array implementation (fastest)
* === false Use Object implementation (most compatible, even IE6)
*
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
* Opera 11.6+, iOS 4.2+.
*
* Due to various browser bugs, sometimes the Object implementation will be used even
* when the browser supports typed arrays.
*
* Note:
*
* - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
*
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
*
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
* incorrect length in some situations.
* We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
* get the Object implementation, which is slower but behaves correctly.
*/
Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
? global.TYPED_ARRAY_SUPPORT
: typedArraySupport()
I believe you are using cli built-in bundler (I wrote it), not webpack.
Yes, nodejs global var global is currently not supported. Also nodejs global vars process and Buffer have similar issues.
The cli doc has a patch to support process and Buffer.
import process from 'process';
window.process = process;
import {Buffer} from 'buffer';
window.Buffer = Buffer;
You can try to add one more patch for global.
window.global = window;
Ok why cli has the issue
cli's tracing algorithm uses rjs (requirejs optimizer) parser, it's bit old, does not detect global vars (technically it does not do variable scope analysis).
I have another WIP bundler called dumber which solved the limitation with a new parser which detects global vars. It automatically patch nodejs global vars at module level based on need.
In long term, we will drop the code for cli built-in bundler, then wrap dumber and make it backward compatible.

why typescript mode don't print error message

i use below command to init a project
react-native init MyAwesomeProject --template typescript
and create a add.tsx file
'use strict';
// this function return string, but it should return number
function add(left: number, right: number): number{
return left + right + 'test';
}
console.log(add('it is a wrong param', 1));
export default add;
add.tsx is imported by App.js. when i run this project, no warning or error is printed, i don't know why
Running react-native init MyAwesomeProject --template typescript sets up a project that can accept typescript code, however it very confusingly doesn't actually set up type checking. Under the hood this is because it sets up Babel (a javscript compiler) which simply strips the TypeScript type annotations. It doesn't actually set up TypeScript itself which would do the actual type checking.
Without seeing your exact project I can't know exactly what you need to fix, but I would suggest following the steps on https://facebook.github.io/react-native/blog/2018/05/07/using-typescript-with-react-native Specifically where it mentions installing typescript ("Adding TypeScript" section), then add a tsconfig.json with {"compilerOptions":{"noEmit": true}}, and then finally you should be able to run ./node_modules/.bin/tsc to actually type check your code.

How to use an idris package installed with a nixpkg in another nixpkg?

Currently I am having some trouble using an Idris package that was installed with nixpkg in another Idris package that depends on it. Both of these packages have been tested on a Debian system, so the problem is not with the Idris code itself, but rather somewhere in how they are being installed on the NixOS system. I believe I can successfully install the first package by calling nix-env -f math.nix -i idris_math where math.nix is defined as:
with import <nixpkgs> { };
stdenv.mkDerivation rec {
name = "idris_math";
idris = haskellPackages.idris;
buildDepends = [ idris ];
src = ./.;
preHook = ''
ln -sv ${idris}/share/x86_64-linux-ghc-8.0.1/${idris.name}/libs $PWD/libs
export IDRIS_LIBRARY_PATH=$PWD/libs
'';
configurePhase = ''
export TARGET=$out/lib/${idris.name}
'';
buildPhase = ''
${idris}/bin/idris --build *.ipkg
'';
installPhase = ''
${idris}/bin/idris --install *.ipkg
${idris}/bin/idris --clean *.ipkg
'';
}
I can then run nix-env -q and see that idris_math has been installed. The second nixpkg looks identical to math.nix, except the name is changed and the buildDepends line is now buildDepends = [ idris idris_math ]. When I try to build or install this package however, I am met with error: undefined variable 'idris_math'. Does anyone know what I am doing wrong, or of a way to fix this?
When you write with import <nixpkgs> {}, every attribute defined in the Nixpkgs set is essentially made into a local variable. This means that, when you write haskellPackages, for example, you are actually referring to the haskellPackages attribute defined by Nixpkgs. You can see all the packages defined this way by looking at the file top-level/all-packages.nix in your Nixpkgs checkout.
Notice that the idris in your buildDepends is referring to the definition of an idris attribute on the previous line. Your new idris_math package isn't similarly defined in this file, or added to the Nixpkgs set anywhere, so you can't get a reference to it by looking for a local variable or for (import <nixpkgs> {}).idris_math, which is basically what is being attempted when you write idris_math in your second derivation.
Depending on what exactly you want to do with your package, you have a couple of options. If you just want to use idris_math as a dependency for another nearby package (or a few), you can just write buildDepends = [ idris (import /path/to/math.nix) ]. This is a very simple way to do what you want, and very likely a good choice if you want to use this is a library when developing Idris packages.
If you want to make idris_math part of the set that you get from import <nixpkgs> {} anywhere on your machine, and to make it easy to nix-env -i, you can try adding it to an overlay. This would require creating a file like ~/.config/nixpkgs/overlays/<my overlay name>/default.nix with contents something like:
self: super:
with super;
{
idris_math = callPackage /path/to/idris_math.nix {};
}
In this scenario, you probably also want to change your idris_math.nix header to be { stdenv, haskellPackages }:, because callPackage looks for this kind of definition and it is useful when tying the knot to combine all the overlays together.

Always "requiring unknown module" when reading json file

bit of an RN newb here. I'm trying to read some json data files:
function loadCategories() {
const ids = ['tl1', 'tl2', 'tl3', 'tl4', 'tl5', 'tl6'];
ids.forEach(function(id) {
var contents = require('../Content/top-level/' + id + ".json.js");
...
});
}
But here I always get an error:
Unhandled JS Exception: Requiring unknown module "../Content/top-level/tl1.json.js".If you are sure the module is there, try restarting the packager or running "npm install".
The files exist and my relative path logic should be OK given the project structure:
ProjectDir
Components
ThisComponent.js
Content
top-level
tl1.json.js
tl2.json.js
...
i.e. the above code is running from ThisComponent.js and trying to access tl1.json.js, etc so I would think the relative path of ../Content/top-level/tl1.json.js would work.
I've tried:
Restarting the packager
Referencing ./Content/top-level/tl1.json.js instead
Referencing /Content/top-level/tl1.json.js instead
I'm on RN 0.36.0. Gotta be something obvious…right?
This isn't possible in React Native because of how the packager works. You have to require files with static string path. You can use a switch statement something like this -
switch (id) {
case 'tl1': return require('../Content/top-level/tl1.json');
case 'tl2': return require('../Content/top-level/tl2.json');
...
}
Also why does your json files have .js extension?