Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Meta
create-react-app
Commits
e280254d
Commit
e280254d
authored
7 years ago
by
Dan Abramov
Committed by
GitHub
7 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Handle errors from port detector (#2182)
parent
46eeabca
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/react-scripts/package.json
+1
-1
packages/react-scripts/package.json
packages/react-scripts/scripts/start.js
+35
-26
packages/react-scripts/scripts/start.js
with
36 additions
and
27 deletions
+36
-27
packages/react-scripts/package.json
+
1
-
1
View file @
e280254d
...
...
@@ -21,7 +21,7 @@
"react-scripts"
:
"./bin/react-scripts.js"
},
"dependencies"
:
{
"@timer/detect-port"
:
"1.1.
2
"
,
"@timer/detect-port"
:
"1.1.
3
"
,
"address"
:
"1.0.1"
,
"autoprefixer"
:
"7.1.0"
,
"babel-core"
:
"6.24.1"
,
...
...
This diff is collapsed.
Click to expand it.
packages/react-scripts/scripts/start.js
+
35
-
26
View file @
e280254d
...
...
@@ -140,33 +140,42 @@ function run(port) {
// We attempt to use the default port but if it is busy, we offer the user to
// run on a different port. `detect()` Promise resolves to the next free port.
detect
(
DEFAULT_PORT
,
HOST
).
then
(
port
=>
{
if
(
port
===
DEFAULT_PORT
)
{
run
(
port
);
return
;
}
detect
(
DEFAULT_PORT
,
HOST
).
then
(
port
=>
{
if
(
port
===
DEFAULT_PORT
)
{
run
(
port
);
return
;
}
if
(
isInteractive
)
{
clearConsole
();
const
existingProcess
=
getProcessForPort
(
DEFAULT_PORT
);
const
question
=
{
type
:
'
confirm
'
,
name
:
'
shouldChangePort
'
,
message
:
chalk
.
yellow
(
`Something is already running on port
${
DEFAULT_PORT
}
.`
+
`
${
existingProcess
?
` Probably:\n
${
existingProcess
}
`
:
''
}
`
)
+
'
\n\n
Would you like to run the app on another port instead?
'
,
default
:
true
,
};
inquirer
.
prompt
(
question
).
then
(
answer
=>
{
if
(
answer
.
shouldChangePort
)
{
run
(
port
);
}
});
}
else
{
if
(
isInteractive
)
{
clearConsole
();
const
existingProcess
=
getProcessForPort
(
DEFAULT_PORT
);
const
question
=
{
type
:
'
confirm
'
,
name
:
'
shouldChangePort
'
,
message
:
chalk
.
yellow
(
`Something is already running on port
${
DEFAULT_PORT
}
.`
+
`
${
existingProcess
?
` Probably:\n
${
existingProcess
}
`
:
''
}
`
)
+
'
\n\n
Would you like to run the app on another port instead?
'
,
default
:
true
,
};
inquirer
.
prompt
(
question
).
then
(
answer
=>
{
if
(
answer
.
shouldChangePort
)
{
run
(
port
);
}
});
}
else
{
console
.
log
(
chalk
.
red
(
`Something is already running on port
${
DEFAULT_PORT
}
.`
)
);
}
},
err
=>
{
console
.
log
(
chalk
.
red
(
`
Something is already running on port
${
DEFAULT_PORT
}
.`
)
chalk
.
red
(
`
Could not find an open port at
${
chalk
.
bold
(
HOST
)
}
.`
)
);
console
.
log
(
'
Network error message:
'
+
err
.
message
||
err
);
console
.
log
();
}
}
);
);
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets