SyntaxError when importing ES6 npm module in Meteor - javascript

I created a new meteor project using meteor create
I ran npm install -S spacy-nlp, which contains some ES6 code
In my server/main.js, I wrote import spacy from 'spacy-nlp'
Upon running meteor, it complained Error: The babel-runtime npm package could not be found in your node_modules. Please run the following command to install it: meteor npm install --save babel-runtime
I installed babel-runtime
Then it complains
W20161120-16:40:30.175(8)? (STDERR) /Users/prashanthcr/code/es6-meteor-test/node_modules/spacy-nlp/src/start-io.js:3
W20161120-16:40:30.176(8)? (STDERR) const { spawn } = require('child_process')
W20161120-16:40:30.176(8)? (STDERR) ^
W20161120-16:40:30.177(8)? (STDERR)
W20161120-16:40:30.178(8)? (STDERR) SyntaxError: Unexpected token {
Not sure where to go from there. Why can't I import an npm package that uses ES6?
I have Node.js 7.1.0 installed globally and I'm using Meteor 1.4.2.3.

Meteor does not compile any files in node_modules to ES5. This means that the code is run unchanged. That is the reason you are getting the error at runtime and not during the build process.
Meteor v1.4.2.x uses node v4.6.2 (you can check the node version using meteor node --version).
This version of node does not normally support destructuring assignment (the const {foo} = ... syntax). This requires using the --harmony_destructuring flag. You can easily test this by running a node shell (REPL) with version 4.x vs 6.x.
Typing the following in 3 terminal sessions:
$ meteor node
$ meteor node --harmony_destructuring
$ node, when node is in v6+
Code:
let bar = () => ({foo: 3}); // 1
let { foo } = bar(); // 2
eval("let { foo } = bar();"); // 3
Statement 1 will run fine.
Statement 2 will not be recognized by node v4 (expect more user input) and will be evaluated as expected by node v6 and v4 with the flag.
Statement 3 forces node to evaluate the expression as a unit without expecting further input by the user, so it will cause node v4 to throw the error you are seeing and will be evaluated properly by node v6 and v4 w/flag.
This means that the error you are facing is a node issue and you need to either:
find a way to get Meteor to run node with the --harmony_destructuring flag.
fork the packages and change the problematic expressions.
fork and add a build configuration to the packages (e.g, a pre-publish step).
wait for Meteor to start using Node v6 (should happen soon, as it is now the stable LTS version).

There is a story about babel-runtime here, which all seems a little confusing to me, but I think the solution is to do
meteor npm install --save babel-runtime
https://forums.meteor.com/t/meteor-1-4-2-1-is-an-important-patch-for-1-4-2-users/31190

Meteor refuses to do anything with what's in node_modules, the thinking being that those packages should already be ready for distribution.
But more and more npm packages are not transpiling from ES6 before packaging so Meteor have been forced to look into this.
For packages that you don't need to modify the solution is easy (once you know it):
Make a symbolic link from node_modules/<package> to somewhere in your app (import maybe). No Meteor thinks that this is code in your application and does whatever is needed with it.

Related

Node application not running on remote server, runned on PC

I have a program developed in javascript that runs in node, it works perfectly on my windows and ubuntu environment but for some reason, it does not work on a remote new server I installed it.
I did the same things I did with my personal environment, install node, install MongoDB, install the packages and run it. but for some reason, it shows an error it didn't show before
Error:
DONE Compiled successfully in 547ms
/home/servinfo/DynamicButtons/build/webpack:/src/routes.js:18
module.exports = app => {
^
TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
at Object.<anonymous> (/home/servinfo/DynamicButtons/build/webpack:/src/routes.js:18:1)
I execute it using backpack-core, I run "npm run dev" and showed me this error(actually bigger but this is what matters)
Usually what I do in these cases:
check node version
check package.json to have all the dependencies including devDependencies for package managers and other building services
remove node_modules/
remove package_lock.json
npm install again
That usually helps

Getting syntax error in Meteor project with node v11.10.0

I am getting the following error in my meteor project. I am using node v11.10.0 in macOs. Thanks in advance.
SyntaxError: Use of const in strict mode.
myprojectpath/node_modules/jsforce/node_modules/faye/node_modules/tough-cookie/node_modules/ip-regex/index.js:3
const v4 =
'(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\.(?:25[0-
^^^^^ SyntaxError: Use of const in strict mode.
You could update your meteor (including node) using meteor update outside the project and then meteor update --release && meteor update --all-packages inside the project and finally enter a meteor npm meteor reset and run the project.
To make sure you run the latest npm packages, you may need to check the npm versions. Very helpful is the tool npm-check-updates which you can install outside of the project directory:
meteor npm install -g npm-check-updates
then cd into your project directory and enter
meteor npm-check-updates
to list your current and the latest available stable versions.
If you rely on the Meteor 1.3 (which I discourage as there are many open security issues in the older Meteor and also in the older Node releases), then you may need to install an older version of jsforce in order to get it run again with the older environment you have.
To make sure you have installed the correct npm packages for your 1.3 you can easily check this against a new created project's package.json using:
meteor create --release X.Y.Z some-app-name # replace X.Y.Z with your Meteor version
meteor npm install
cat package.json

Cannot find module '../build/Release/opencv4nodejs

I am new to OpenCV and node js, trying to learn OpenCV in node js.
I came across opencv4nodejs which I found best for learning.
I have followed all steps to install OpenCV and setting environment variables for OpenCV and done npm install opencv4nodejs also. able to run Quick start code given but when I try to run example machineLearningOCR.js from examples folder I get error Error: Cannot find module '../build/Release/opencv4nodejs'
I run command node machineLearningOCR.js from cmd but getting error mentioned above on line const cv = require('../');
How to run examples given in opencv4nodejs?
If you cloned the repository and want to use the examples directly from the examples folder then you have to npm install in the root directory first to build the module.
Optionally you can npm install opencv4nodejs in any project directory, copy the examples into that directory and replace const cv = require('../'); with const cv = require('opencv4nodejs');.
You can also directly submit an issue here: https://github.com/justadudewhohacks/opencv4nodejs/issues
I had the same problem and I did solve the issue with the following steps.
First all of. I checked the npm version, for this case I recommend you updated or pass your software resources at the next version.
NodeJs 14.16.0
NodeJs version: 14.16.0. You can verify the version with this command if you had another NodeJs version installed
node --version
Npm version: 6.4.11 You need verify if you had this version installed only you will able to validate this if you have NodeJs but if you didn't have node you can install the version I recommend you
npm --version
After you set the NodeJs and npm versions you need to verify the following things
Have visual studio 2015 or latest with the development for desktop component
Have cmake program installed
Have git bash
Have Java or the language you will to work
Have the environment variables for the above programs I mentioned
Then you can try again to install open Cv
You need to reopen another or new terminal and then you will execute this command
npm install --save openc4nodejs
And then
npm install -g openc4nodejs
After than or before don't forget to install appium I recommend you 1.19.1 version
You can verify if you have appium with opencv with open Cv doctor you can run appium-doctor and check if the Open cv component are present.
For to install appium doctor you can run this command, npm install -g appium-doctor
I hope this answers will be helpful for you
Autor: Eder Carbonero

All NPM COMMAND not working even I updated .bash_profile

I used npm for several months.
But after I install python/django and virtual environment, it's not working anymore.
The error is smething like this.
sudo npm install -g react-native-cli
module.js:341
throw err;
^Error: Cannot find module './cache/caching-client.js'
I used npm for several days but this happened first time. I searched to solve issue and found this link
Installing MEAN Stack: npm -v module.js: 338 throw err; Error: Cannot find module './cache/caching-client.js'.
But not working.
echo $NODE_PATH
/usr/local/lib/node_modules
And it occurs on all npm commands.
npm -v
npm init -y
I reinstalled the node.js again and it worked.:)
f you added React Native manually to your project, make sure you have included all the relevant dependencies that you are using, like RCTText.xcodeproj, RCTImage.xcodeproj. Next, the binaries built by these dependencies have to be linked to your app binary. Use the Linked Frameworks and Binaries section in the Xcode project settings. More detailed steps are here: Linking Libraries.
If you are using CocoaPods, verify that you have added React along with the subspecs to the Podfile. For example, if you were using the , and fetch() APIs, you would need to add these in your Podfile:
for more see this
https://www.npmjs.com/package/react-native-winjs-cli/tutorial

Using npm modules with TypeScript - can't even get the simplest example working

I would like to use npm modules within a Typescript program. Fortunately, I came across this which looks very easy and does indeed seem to work. I figured I would try and add another package, just to get the hang of it. So I forked it and made one relatively simple commit.
Here's all the things I did in my commit:
Added pubsub-js to my dependencies in package.json, so it will install on npm install.
Set up tsd, used it to install the TypeScript definition for pubsub-js, and set it to automatically run on npm install.
Modified index.ts to include the installed definition:
/// <reference path="./typings/pubsubjs/pubsub.d.ts" />
and to import the installed package:
import PubSub = require('pubsub-js');
Unfortunately, this doesn't work. I get this error:
$ npm install
$ npm test
> demo-typescript-node-minimal#0.0.1 test /home/dumbmatter/projects/mini/demo-typescript-node-minimal
> tsc index.ts --module commonjs && node ./index
index.ts(10,25): error TS2307: Cannot find module 'pubsub-js'.
npm ERR! Test failed. See above for more details.
(If you want to it for yourself, clone my repo, run npm install, and then npm test.)
And I want to reiterate, the original version (without my commit, straight from the original repo) does in fact work:
$ git checkout d002c0dffc9d9f65aca465b0fc6a279bcd23202d
$ npm test
> demo-typescript-node-minimal#0.0.1 test /home/dumbmatter/projects/mini/demo-typescript-node-minimal
> tsc index.ts --module commonjs; node ./index
[ 'abc', index: 0, input: 'abcdefgh' ]
Hello Dave
So what gives? Why did my attempt fail so miserably?
I would also appreciate any advice on the wisdom of using npm packages in TypeScript in general. Is it just to error prone for real use? If so, and you found yourself in the situation where you wanted some generic pubsub library in a TypeScript program you were using... what would you do? Write your own?
The problem is that pubsub.d.ts doesn't contain a definition for the CommonJS module "pubsub-js" (instead it only defines a global object PubSubJS).
The best fix would be to edit that file; at the bottom add:
declare module "pubsub-js" {
export = PubSub;
}
Most .d.ts files already include such a definition when a CommonJS or AMD module is available for a given package.

Categories

Resources