-
-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Can't use native node modules like fs #3074
Comments
What package are you trying to use? |
import * as fs from 'fs'; Just the local nodejs module I want to use. |
Hmm, you definitely can't use fs like that so I suppose I'd expect this to break, was it running for code that was strictly ran server side? Is it feasible for you to take it out of your main app? I guess I'd need more context about what you're doing. |
sure, By default is client render, SSR is a consider, the thing I do is for markdown render like this: /**
* @desc render Markdown Language for React
*/
import * as fs from 'fs';
import React from 'react';
import ReactMarkdown from 'react-markdown';
class Markdown extends React.Component {
constructor(props) {
super(props);
this.state = {
doc: 'null',
};
}
componentDidMount() {
fs.readFile('./../md-documents/eslint.md', 'utf8', (err, eslint) => {
if (err) {
return console.error(err);
}
console.log(`async read file: ${eslint.toString()}`);
return this.setState({
doc: eslint,
});
});
}
render() {
return <ReactMarkdown className="markdown" source={this.state.doc} />;
}
}
export default Markdown; |
Hmm, I see ... I'm going to ask @gaearon to share his input. This seems like an odd use case to me (I suppose it makes sense in a SSR environment), but we don't support SSR. If you've ejected (which it seems like you have), you can remove Does switching |
I create this project today, and once I meet this question I tried to delete this config in webpack.x.x both dev and prod in the react-scripts(thoughs It's not a good idea for changing node_modules). It doen't useful, |
Ah, yes, I just checked and we've stubbed it as empty for over a year now. Hmm, I'd suggest working around this so that you don't require |
Thanks!🤣 Now I import /.md$/ file with /.md.js$/ the pseudo method for string to use, and I'l try your sugest that only use it when rendering server side as a property. |
Closing as we settled on the solution being re architecting where fs is used. |
It's like a problem not a bug.
when I want to use 'fs' module in my project created by
create-react-app
, I got this question:searched for sometimes, I get a config with:
try to changed it for other condition is also failed.
can I use modules listed in the config by anyways ?
The text was updated successfully, but these errors were encountered: