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

Fs module error while using package. #26

Closed
devanshSingh5656 opened this issue Jun 26, 2021 · 10 comments
Closed

Fs module error while using package. #26

devanshSingh5656 opened this issue Jun 26, 2021 · 10 comments

Comments

@devanshSingh5656
Copy link

Module not found: Can't resolve 'fs'.

Capture1

i try to resolve it so i use this in NEXT config file the error resolve and it work perfectly in local

BUT WHEN DEPLOY TO SERVER IT WON'T WORK.
Capture

webpack: (config, { isServer }) => {
// Fixes npm packages that depend on fs module
if (!isServer) {
config.node = {
fs: "empty",
};
}

PLEASE PROVIDE HELP ASAP.

@jellydn
Copy link
Owner

jellydn commented Jun 26, 2021

Hi @devanshSingh5656. Thank you for your report. Could you tell me the usage? Which one are you using? https://github.com/jellydn/next-swagger-doc#usage-1-create-an-single-api-document or https://github.com/jellydn/next-swagger-doc#usage-2-use-nextjs-api-route-for-create-swagger-json-spec

It would be helpful for me investigating if you share the package.json and next.config.js. Thanks.

@jellydn
Copy link
Owner

jellydn commented Jun 26, 2021

At first glance, I guess the fs is a native module on NodeJs and you got the error with fs module which means you're calling serverside function from the browser. 🤔

@jellydn
Copy link
Owner

jellydn commented Jun 26, 2021

Please check the example app https://github.com/jellydn/next-swagger-doc/blob/main/example/README.md if you want to see how it works. Thanks.

@devanshSingh5656
Copy link
Author

devanshSingh5656 commented Jun 26, 2021

i am using createSwaggerSpec for multiple api's but it throws the error

but when i use with changes in next config

module.exports = {

webpack(config,{ isServer }) {
config.module.rules.push({
test: /.svg$/,
use: ["@svgr/webpack"],
});
if (!isServer) {
config.node = {
fs: 'empty'
};
}

return config;

},
};

it works but when i deployed it on server api's are not visible
Capture

package.json

{
"name": "api",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@svgr/webpack": "^5.5.0",
"axios": "^0.21.1",
"bcrypt": "^5.0.1",
"bcryptjs": "^2.4.3",
"bootstrap": "^5.0.1",
"cookie-parser": "^1.4.5",
"cookies": "^0.8.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.12.9",
"next": "10.2.0",
"next-api-url": "^1.0.0",
"next-swagger-doc": "^0.1.5",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-redux": "^7.2.4",
"reactjs-popup": "^2.0.4",
"redux": "^4.1.0",
"swagger-jsdoc": "^6.1.0",
"swagger-ui-react": "^3.51.0",
"swr": "^0.5.6"
}
}

@jellydn
Copy link
Owner

jellydn commented Jun 26, 2021

re.

it works but when i deployed it on server api's are not visible

So it's working on local but it's showing empty on production deployment, right? Interesting 🤔 . How do you set up the deployment? It could give me some insights to think about this. Thanks.

@jellydn
Copy link
Owner

jellydn commented Jun 26, 2021

Hi @devanshSingh5656 Please check out the latest version https://github.com/jellydn/next-swagger-doc/releases/tag/v0.1.7 Let me know if that works for you. Thanks.

@jellydn jellydn closed this as completed Jun 26, 2021
@devanshSingh5656
Copy link
Author

used vercel deployment

@jellydn
Copy link
Owner

jellydn commented Jun 26, 2021

It shouldn't be an issue anymore. My example app is also deployed to vercel.

@devanshSingh5656
Copy link
Author

can you make the package available on npm?

@jellydn
Copy link
Owner

jellydn commented Jun 26, 2021

It's published on npm already.

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