Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devserver associated setting may not come to effect when use function #172

Closed
DamonMuscle opened this issue Jun 27, 2020 · 3 comments
Closed

Comments

@DamonMuscle
Copy link

module.exports = {
/config 1/
devServer: (devServerConfig, { env, paths, proxy, allowedHost }) => {
devServerConfig.port = 3009;
return devServerConfig;
},
/config 2/
devServer: (devServerConfig, { env, paths, proxy, allowedHost }) => {
return { ...devServerConfig, port: 3009 };
},
/config 3/
devServer: {
port: 3009,
},
};
When I use config 1 or 2, the setting will not come to effect. Only config 3 works fine.

create-react-app -V
3.4.1

"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"@types/jest": "^24.9.1",
"@types/node": "^12.12.47",
"@types/react": "^16.9.41",
"@types/react-dom": "^16.9.8",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1",
"typescript": "^3.7.5"
},
"devDependencies": {
"@craco/craco": "^5.6.4"
}

@patricklafrance
Copy link
Contributor

Hi @DamonMuscle

Not much I can do for this one.

With option 3 CRACO set CRA PORT env variable (https://create-react-app.dev/docs/advanced-configuration) which is then pick up by CRA here: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/scripts/start.js#L60

This is why it works.

When you use the function format of CRACO devServer, sadly, the function is executed at runtime when the devServer proxy is created by CRA. This is too late to set an environment var and CRA doesn't acknowled the port prop of the devServer config.

@DamonMuscle
Copy link
Author

Hi @patricklafrance

Thank you for your reply.

@stale
Copy link

stale bot commented Sep 1, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Sep 1, 2020
@stale stale bot closed this as completed Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants