react-native start unexpected token - javascript

I'm getting an error on the start command when using react-native. The file
projectName/node_modules/#babel/core/lib/transformation/file/file.js
on line 63 is giving the error
constructor(options, {
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Module._extensions..js (module.js:417:10)
at Object.require.extensions.(anonymous function) [as .js] (/home/cread/WHOOP-ReactNative/whoopApp/node_modules/babel-register/lib/node.js:152:7)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/cread/WHOOP-ReactNative/whoopApp/node_modules/#babel/core/lib/index.js:123:36)
at Module._compile (module.js:410:26)
Here is my package.json file
{
"name": *name*,
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.3.0-alpha.2",
"react-native": "0.54.2",
"react-native-elements": "^0.19.1",
"react-native-keyboard-aware-scroll-view": "^0.5.0",
"react-native-modal-dropdown": "^0.6.2",
"react-native-sound": "0.10.9",
"react-native-vector-icons": "^4.5.0",
"react-navigation": "^1.5.8"
},
"devDependencies": {
"babel-jest": "23.0.0-alpha.0",
"babel-preset-react-native": "4.0.0",
"jest": "22.4.2",
"react-test-renderer": "16.3.0-alpha.2"
},
"jest": {
"preset": "react-native"
}
}
I've tried deleting my node_modules file, clearing the npm cache, and reinstalling but to no avail. The problem seems to be in the cli.js file.

I was using the last version of the react-native and nodejs. Unfortunately, I needed to go back to the version 8.11.2. In my case, it is resolved.
I removed the node_modules dir.
$ rm -rf node_modules
$ nvm install 8.11.2
$ nvm use 8.11.2
$ npm install react-native#0.54.1

Related

Converting Js to Ts error cannot find module

Currently converting my project from JS to TS, working on the server side. Here is the error code.
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module
'/Users/steven/Documents/codingDojo/Mern/tomrotten/server/index.js'
at Function.Module._resolveFilename
(internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Function.executeUserEntryPoint [as runMain]
(internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
[nodemon] app crashed - waiting for file changes before starting...
here are a list of my dependencies:
"dependencies": {
"#material-ui/lab": "^4.0.0-alpha.58",
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"express-session": "^1.17.1",
"jsonwebtoken": "^8.5.1",
"mysql": "^2.18.1",
"mysql2": "^2.2.5",
"sequelize": "^6.5.0",
"sqlite3": "^5.0.1"
This happens because it is missing a dependency, either because the dependency is not imported, or it is but it isn't installed. Do you have import cjr from "cjr" or something like that at the top of server/index.js? Have you done npm install?

Cannot find module 'styled-jsx/style' in production firebase

I built a Next js app for which am trying to add some css.
Tried using the built in styled-jsx css lib . All works fine in local.
Now, when I upload the same in firebase hosting and try SSR using firebase functions . I get this error .
Question is : If styled jsx is part of next js then why am seeing this error . That too only in production
Using next js 6+ .
I know i can always add styled jsx as a dependency , but trying to understand why its not working since its supposed to be built in to next js already.
Thanks in Advance!
This is my package.json content :
"dependencies": {
"#babel/runtime": "^7.1.2",
"firebase": "^5.5.3",
"firebase-admin": "^5.12.1",
"firebase-functions": "^2.0.5",
"next": "^6.1.1",
"react": "^16.4.0",
"react-dom": "^16.4.0"
},
"devDependencies": {
"#babel/cli": "^7.1.2",
"#babel/core": "^7.1.2",
"#babel/preset-env": "^7.1.0",
"#firebase/app-types": "^0.3.2",
"cpx": "^1.5.0",
"firebase-tools": "^3.18.6",
"prettier": "^1.13.5",
"rimraf": "^2.6.2"
}
Error :
Error: Cannot find module 'styled-jsx/style'
at Function.Module._resolveFilename (module.js:476:15)
at Function.Module._load (module.js:424:25)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/user_code/next/server/bundles/pages/mystatus.js:245:18)
at __webpack_require__ (webpack:/webpack/bootstrap 51b5f67292a9fe79adac:21:0)
at Object.<anonymous> (/user_code/next/server/bundles/pages/mystatus.js:101:75)
at __webpack_require__ (webpack:/webpack/bootstrap 51b5f67292a9fe79adac:21:0)
at Object.module.exports.Object.defineProperty.value (/user_code/next/server/bundles/pages/mystatus.js:89:18)
at __webpack_require__ (webpack:/webpack/bootstrap 51b5f67292a9fe79adac:21:0) code: 'MODULE_NOT_FOUND', sourceMapsApplied:

Cannot read property https of undefined error in firebase functions

I'm following this youtube firebase official tutorial on cloud functions for server-side react rendering.
(I followed the exact directory structure as the video by the way.)
But I'm getting an error whenever I try to serve it:
i functions: Preparing to emulate functions.
⚠ hosting: Port 5000 is not available. Trying another port...
i hosting: Serving hosting files from: dev
✔ hosting: Local server: http://localhost:5004
⚠ functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
⚠ functions: Error from emulator. Error occurred while parsing your function triggers.
TypeError: Cannot read property 'https' of undefined
at Object.<anonymous> (/Users/mac/Documents/React-Projects/React-js/Cards/functions/index.js:35:54)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at /Users/mac/.nvm/versions/node/v6.11.5/lib/node_modules/firebase-tools/lib/triggerParser.js:21:11
at Object.<anonymous> (/Users/mac/.nvm/versions/node/v6.11.5/lib/node_modules/firebase-tools/lib/triggerParser.js:75:3)
I have tried npm i --save firebase-functions as it said but still getting error.
firebase.json:
{
"hosting": {
"public": "dev",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites":[{
"source": "**",
"function": "main"
}]
}
}
index.js in the root of project folder:
import React from 'react';
import { renderToString } from 'react-dom';
import express from 'express';
import Test from './src/components/Test/Test';
import functions from 'firebase-functions';
const app = express();
app.get('**', (req, res) => {
const html = renderToString(<Test />);
res.send(html);
});
export let main = functions.https.onRequest(app);
package.json:
{
"name": "Cards",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack --mode development",
"start": "webpack-dev-server --open --hot --mode development",
"build": "webpack -p --config webpack.prod.config.js",
"babel": "babel src -d functions/src && babel index.js -d functions"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#material-ui/core": "^1.3.0",
"#material-ui/icons": "^1.1.0",
"firebase": "^5.2.0",
"react": "^16.4.1",
"react-dom": "^16.4.1"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"firebase-admin": "^5.12.1",
"firebase-functions": "^1.1.0",
"firebase-tools": "^3.19.1",
"webpack": "^4.14.0",
"webpack-dev-server": "^3.1.4"
}
}
By looking at the error, it is pointing at functions.https.onRequest(app); line in the index.js file.
I have also checked in the functions get started guide and it has functions.https.onRequest(...).
So, where is the problem and how can I solve it?
System details:
macOS: 10.13.4
nvm: 0.33.11
node: 6.11.5
npm: 3.10.10
You should do:
import * as functions from 'firebase-functions'
because 'firebase-functions' obviously doesn't seem to have a default export
or you can do:
import { https } from 'firebase-functions'
but remember to add to this impot any other functions that you might use in your code.

Cannot read property 'Store' with RedisStore and Node.js

I'm experiencing the following error when I try to run my Node.js app:
Starting child process with 'node ./app.js'
C:\Users\Julian\OneDrive\Documents\Websites\Node\node_modules\connect-redis\lib\connect-redis.js:33
var Store = connect.session.Store;
^
TypeError: Cannot read property 'Store' of undefined
at module.exports (C:\Users\Julian\OneDrive\Documents\Websites\Node\node_modules\connect-redis\lib\connect-redis.js:33:30)
at Object.<anonymous> (C:\Users\Julian\OneDrive\Documents\Websites\Node\app.js:9:42)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.runMain (module.js:590:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
Program node ./app.js exited with code 1
Starting child process with 'node ./app.js'
Received SIGINT, killing child process...
Parent process exiting, terminating child...
Terminate batch job (Y/N)? y
My package.json file is as follows:
{
"name": "NodeChat",
"version": "0.0.0",
"main": "app.js",
"scripts": {
"stop": "echo not implemented",
"start": "supervisor ./app.js"
},
"dependencies": {
"connect-flash": "0.1.1",
"connect-redis": "1.4.7",
"cookie-parser": "1.4.3",
"ejs": "0.8.5",
"express": "4.6.1",
"express-partials": "0.2.0",
"express-session": "1.14.2",
"redis": "0.10.1"
}
}
I thought it might be a compatibility issue, but I believe I'm running a compatible version of connect-redis#1.4.7. I have an instance of Redis running.
Updating "connect-redis": "1.4.7" to 1.5.0 solved the problem for me.

How to preserve correct line numbers with node js and babel

I have the following setup and have an issue with my error/stack trace am i missing something ?
package.json looks like:
{
"name": "xxxxxx",
"main": "server.js",
"private": true,
"scripts": {
"start": "nodemon --exec ./node_modules/.bin/babel-node server.js"
},
"dependencies": {
"babel": "^6.5.2",
"babel-cli": "^6.6.5",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"babel-runtime": "^6.6.1"
}
}
.babelrc looks like:
{
presets: ["es2015", "stage-0", "react"],
sourceMap: 'inline',
retainLines: true
}
server.js looks like:
let aVar = '';
throw new Error('some error');
import errorHandler from './app/middlewares/error_handler';
My stack trace is crazy
module.js:341
throw err;
^
Error: Cannot find module 'bugsnag'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/home/projectName/lib/util/error.js:14:113)
at Module._compile (module.js:413:34)
at loader (/home/projectName/node_modules/babel-register/lib/node.js:126:5)
at Object.require.extensions.(anonymous function) [as .js] (/home/projectName/node_modules/babel-register/lib/node.js:136:7)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/home/projectName/app/middlewares/error_handler.js:11:91)
at Module._compile (module.js:413:34)
at loader (/home/projectName/node_modules/babel-register/lib/node.js:126:5)
at Object.require.extensions.(anonymous function) [as .js] (/home/projectName/node_modules/babel-register/lib/node.js:136:7)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/home/projectName/server.js:15:22)
at Module._compile (module.js:413:34)
As you can see this does not look right and really hard to follow. i am sure there's a way to fix that.
It looks like you are missing 'bugsnag' module.
Try:
npm install -g bugsnag

Categories

Resources