When I attempt to compile my app, I get the attached error despite the fact that I am not explicitly attempting to import crypto in any of the files I have written myself. It seems that it is imported in a file automatically present in the node_modules folder. Is anyone familiar with the given error?error
The package at "node_modules\reques\lib\helpers.js" attempted to import the Node standard library module "crypto". It failed because the native React runtime does not include the Node standard library. Read more at https://docs.expo.io/introduction/faq/#can-i-use-nodejs-packages-with-expo
You can't use the request package, it included native Node.js libraries that are not supported in React Native. Use another request library that is made for React native.
This is because a dependency in your react-native project is using the crypto library.
One of the dependencies installed is not made for react-native and is made to run on the server. Find out which dependency that is and you can change it to a react-native compatible library to fix the issue.
Related
I'm working on an emberjs application that uses several other custom ember addons, one of which we're adding is a new dependency on mathjs (https://mathjs.org/) to do some expression parsing. It isn't clear though what is the correct way to keep the configuration of that dependency on mathjs with only the addon that uses it. Is there a "right" way to do this in ember?
What we ended up doing was just installing the mathjs package into our main app's node_modules, then exposing the library in the browser by doing an app.import('node_modules/mathjs/dist/math.min.js') in our ember-cli-build.js file. This is obviously non-ideal because it means that any app using the custom addon must also do this extra setup to expose this dependency of the addon.
FWIW, we initially tried to just install the mathjs dependency into the addon's node_modules, then we imported it in the component of the addon where it's used. But then the browser said that the mathjs module couldn't be imported from the addon.
You should let ember-auto-import manage this for you. For this:
add math.js to your dependencies of your addon (not devDependencies).
use import syntax to import it in your addon.
For the import syntax you need to be aware that some modules only have a default export which is a object exporting properties while others have individual exports. So its either
import { pi, atan2 } from 'mathjs' or import mathjs from 'mathjs'.
your host app should then have your addon in devDependencies.
Only use app.import syntax if you use something that does not support modules at all.
I'm developing a library in TypeScript.
This library uses the https://github.com/Simonwep/pickr library.
I would like to make my library available so users can use it, but question is: do I need to bundle pickr library or just put a reference in the package.json?
I tried to use the library in a sample project and in dev mode all works since it loads from node_modules, but when I build the project and try to load it fails to load it.
It works only by importing the library using
<script src="https://cdn.jsdelivr.net/npm/#simonwep/pickr/dist/pickr.min.js"></script>
If library will be used in a web browser I made it so the script tag is automatically added.
But what if someone will use the library in an ionic project for instance which will run on a tablet?
In this case Pickr library needs to bundled in the final build.
Is this an automatic process? What's the correct way of using a third-party library in this case?
If you want pickr to get bundled with your code you will have to
List it under dependencies
Import it in your code (see pickr docs)
If its not imported in your code it wont be bundled.
If you want to tell the user to manually add pickr when he uses your module you can list pickr as a peerDependency in your package.json
I am writing a javascript library that is npm linked to my meteor app. I didn't yet publish the library to npm so it is only local.
Now my problem is, that I want to debug inside the library while using it in my meteor app.
I can debug the meteor app components and using a sourcemap and a standalone html test page also the library itself. But as soon as I use import Library from 'library' in meteor it minifies, uglifies and mangles it.
Is there a way to tell either meteor's build system or my browser to use the library's source map?
Thanks in advance
You can try removing the Meteor minifier package until you need it again:
meteor remove standard-minifier-js
I'm a newbie to Meteor.js and working on a project where I'm also using Redux so I added the kyutaekang:redux package. The problem is that I don't know how to import Redux to use it. I tried:
import { createStore } from 'redux';,
but when I start the app I get
[Error: Unable to fetch "redux". Only file URLs of the form file:/// allowed running in Node.].
Meteor does not yet support the ES2015 import out of the box (might be available in 1.3.0). Therefore, you will need a modern module bundler, as also described in the package's Readme file:
This assumes that you’re using npm package manager with a module bundler like Webpack or Browserify to consume CommonJS modules.
You can take a look at this excellent example by Adam Brodzinski to get you started.
Edit:
After taking a closer look at the package, it does not seem to contain any code.
Nonetheless, my recommendation about Adam's repo (or his other repo, pointed in the comments) still remains as a nice, clean implementation.
I want to use the Perf stuff. It seems that if I do:
var React = require('react/addons');
in my own modules then libraries (react-bootstrap, react-router etc.) end up using another copy of plain react and things break. I am using browserify.
Is there a fix or another way to do this?
Requiring react and react/addons will give you the same object. react/addons requires the same module that react does (lib/React), and react/addons even mutates that object so that anyone requiring react will get the addons as well.
If you end up with multiple versions of React in your bundle, it's because the libraries you use have react as a dependency instead of a peer dependency. You should use npm dedupe to avoid that. But react-router has react as a peer dependency, so react-router will get the same react module instance as your module (with the addons). Don't know about the other packages you use that depend on React though.
It turns out the problem was with my gulpfile. Tx for the comments about looking for a browserify shim that lead me to the solution:
My browserify task (from React JS workflow, part 2) builds separate vendors.js (libs) and main.js (my app) bundles during development using browserify.external(..) to exclude the libs from main.js. I just had to add "react/addons" as an external lib along with "react".
The issue is explained here:
https://github.com/substack/node-browserify/issues/1161