question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SyntaxError: /myObject/node_modules/cesium/index.js: 'return' outside of function (9:4)

See original GitHub issue

hello, I created a new react project and found that it didn’t work. Throw the following error:

Failed to compile.

./node_modules/cesium/index.js
SyntaxError: /myObject/node_modules/cesium/index.js: 'return' outside of function (9:4)

   7 | if (process.env.NODE_ENV === 'production') {
   8 |     module.exports = require(path.join(__dirname, 'Build/Cesium/Cesium'));
>  9 |     return;
     |     ^
  10 | }
  11 | 
  12 | // Otherwise, use un-optimized requirejs modules for improved error checking. For example 'development' mode


image

/src/App.js

import React from "react";
import { hot } from "react-hot-loader";
import { Cartesian3 } from "cesium";
import { Viewer, Entity } from "resium";

const App = () => (
    <Viewer full>
        <Entity
            name="Tokyo"
            position={Cartesian3.fromDegrees(139.767052, 35.681167, 100)}
            point={{ pixelSize: 10 }}
            description="hoge"
        />
    </Viewer>
);

export default hot(module)(App);

package.json

"dependencies": {
    "cesium": "^1.55.0",
    "react": "^16.8.4",
    "react-dom": "^16.8.4",
    "react-hot-loader": "^4.8.0",
    "react-scripts": "2.1.8",
    "resium": "^1.3.0"
  },

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
giantsscommented, Mar 12, 2019

Modify App.js to this way, it will run normally.

import React from "react";
import { hot } from "react-hot-loader";
import { Cartesian3 } from "cesium";  //change
import { Viewer, Entity } from "resium"; //change

const App = () => (
    <Viewer full>
        <Entity
            name="Tokyo"
            position={Cartesian3.fromDegrees(139.767052, 35.681167, 100)}
            point={{ pixelSize: 10 }}
            description="hoge"
        />
    </Viewer>
);

export default hot(module)(App);
0reactions
giantsscommented, Mar 12, 2019

When I replaced it with import { Viewer, Entity, Color } from "cesium";, threw an error, I don’t know what happened.

image

My App.js

import React from "react";
import { hot } from "react-hot-loader";
// import { Cartesian3 } from "cesium";
import { Viewer, Entity, Cartesian3 } from "cesium";

const App = () => (
    <Viewer full>
        <Entity
            name="Tokyo"
            position={Cartesian3.fromDegrees(139.767052, 35.681167, 100)}
            point={{ pixelSize: 10 }}
            description="hoge"
        />
    </Viewer>
);

export default hot(module)(App);
Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: return not in function - JavaScript - MDN Web Docs
The JavaScript exception "return (or yield) not in function" occurs when a return or yield statement is called outside of a function.
Read more >
SyntaxError: script.js: 'return' outside of function `r` (6:4)
SyntaxError : script.js: 'return' outside of function `r` (6:4). I think I'm inputting something wrong or i got my parameters wrong?
Read more >
SyntaxError: 'Return' Outside Function in Python - STechies
Syntaxerror : 'return' outside function. This syntax error is nothing but a simple indentation error, generally, this error occurs when the indent or...
Read more >
Return outside function error in Python - Stack Overflow
You can only return from inside a function and not from a loop. It seems like your return should be outside the while...
Read more >
[resolved] SyntaxError: 'return' statement outside of function 6/9
Can someone please tell me specifically why I am getting the message “SyntaxError: 'return' statement outside of function.” I have tried over and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found