6

I am facing this issue from last day.. No solution for this error Complete error log is mentioned below

var v3Err;
try {
    module.exports = require("chokidar");
    return;
} catch(e) {
    v3Err = e;
}
      

Error occurs in 'return' outside of function (4:2)

SyntaxError: E:\test\node_modules\watchpack\lib\chokidar.js: 'return' outside of function (4:2)

at Object._raise (E:\test\node_modules@babel\parser\src\parser\error.js:60:45) at Object.raiseWithData (E:\test\node_modules@babel\parser\src\parser\error.js:55:17) at Object.raise (E:\test\node_modules@babel\parser\src\parser\error.js:39:17) at Object.parseReturnStatement (E:\test\node_modules@babel\parser\src\parser\statement.js:563:12) at Object.parseStatementContent (E:\test\node_modules@babel\parser\src\parser\statement.js:197:21) at Object.parseStatement (E:\test\node_modules@babel\parser\src\parser\statement.js:151:17) at Object.parseBlockOrModuleBlockBody (E:\test\node_modules@babel\parser\src\parser\statement.js:873:25) at Object.parseBlockBody (E:\test\node_modules@babel\parser\src\parser\statement.js:843:10) at Object.parseBlock (E:\test\node_modules@babel\parser\src\parser\statement.js:813:10) at Object.parseStatementContent (E:\test\node_modules@babel\parser\src\parser\statement.js:218:21) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! forbes-me@1.0.0 start: pawjs --no-cache --config=./pawconfig.json --env=development start npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the forbes-me@1.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\glowlogix\AppData\Roaming\npm-cache_logs\2020-08-17T09_19_41_742Z-debug.log

jawad zahoor
  • 81
  • 1
  • 6
  • 1
    You shouldn't ever need to wrap `module.exports` in a try catch. If it's cos you think `module` might not be defined, you might be mixing up module types. Check out this post for an example: https://stackoverflow.com/questions/35659956/module-not-defined – Jayce444 Aug 17 '20 at 09:56

4 Answers4

28

I was facing the same problem in my project. An autocomplete (due to a typo) automatically added an import to my file. When i removed it my problem was solved. So i advice you to check your modules for unnecessary imports.

example of my auto added import

8

I faced a similar issue in my code, an unwanted autocmplete addded and unnecessary import in my code.

import { IgnorePlugin } from 'webpack';

Removed this import and it got back to normal.

3

unwanted import is added for me. removed and it worked.

  • import { LoaderOptionsPlugin } from 'webpack';
Community
  • 1
  • 1
Vinay Patel
  • 131
  • 1
  • 3
0

Uwanted Imports of modules from webpack in any of the components caused me the error,search through every files to check if there is any unwanted imports which might have crawled in due to auto-type