npm开始抛出错误状态1要求不是函数

时间:2019-03-25 23:31:15

标签: javascript reactjs npm

运行npm start时出现以下错误。

> app@0.1.0 start /Users/user/Desktop/react-tutorial
> react-scripts start

require(...) is not a function
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the app@0.1.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:

这是实际错误

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using npm@6.4.1
3 info using node@v10.15.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle app@0.1.0~prestart: app@0.1.0
6 info lifecycle app@0.1.0~start: app@0.1.0
7 verbose lifecycle app@0.1.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle app@0.1.0~start: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/user/Desktop/react-tutorial/node_modules/.bin:/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin:/Users/user/Library/Android/sdk/tools:/Users/user/Library/Android/sdk/platform-tools:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Xamarin Workbooks.app/Contents/SharedSupport/path-bin:/opt/local/share/java/android-sdk-macosx/platform-tools:/Users/user/.android-sdk-macosx/platform-tools/:/Users/user/.android-sdk-macosx/platform-tools/:/Users/user/Library/Android/sdk/platform-tools/
9 verbose lifecycle app@0.1.0~start: CWD: /Users/user/Desktop/react-tutorial
10 silly lifecycle app@0.1.0~start: Args: [ '-c', 'react-scripts start' ]
11 silly lifecycle app@0.1.0~start: Returned: code: 1  signal: null
12 info lifecycle app@0.1.0~start: Failed to exec start script
13 verbose stack Error: app@0.1.0 start: `react-scripts start`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:962:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
14 verbose pkgid app@0.1.0
15 verbose cwd /Users/user/Desktop/react-tutorial
16 verbose Darwin 16.7.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
18 verbose node v10.15.0
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error app@0.1.0 start: `react-scripts start`
22 error Exit status 1
23 error Failed at the app@0.1.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

当我重新启动计算机时,这才刚刚开始发生...为什么

我找不到我正在调用require()的地方...也许我安装了一个插件?

3 个答案:

答案 0 :(得分:1)

  1. 删除nodes_modules
  2. npm install -g npm
  3. npm install & npm install -D
  4. npm run start

答案 1 :(得分:1)

就我而言,已经在项目级别创建了setupProxy.js文件,后来我删除了其中的配置,但没有删除该文件。因此,引发了上述错误。要解决此问题,请根据需要尝试以下方法之一,

  1. 更新setupProxy.js中的正确配置
  2. 如果不需要,请删除setupProxy.js
  3. 不要将setupProxy.js保留为空文件

答案 2 :(得分:1)

感谢@Srinivas 在问题评论中的回复。

删除生成的 setupProxy.js 文件。如果您想使用代理,请将其添加到您的 package.json 文件中。

  "proxy": "http://localhost:3000",

对于像这样的 setupProxy.js 文件:

const proxy = require('http-proxy-middleware');

// tells the browser to direct any relative reference paths to the below 
// domain instead of our own
module.exports = function(app) {
  app.use(proxy('/api/*', { target: 'http://localhost:3000' }));*/
};