swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

ANgular build require Path on build

Open Mehdi-MST opened this issue 1 year ago • 6 comments

when we build Angular app it gives an error on node_modules/swagger-ui-dist/absolute-path.js:9:19:

const getAbsoluteFSPath = function () { // detect whether we are running in a browser or nodejs if (typeof module !== "undefined" && module.exports) { return require("path").resolve(__dirname) } throw new Error('getAbsoluteFSPath can only be called within a Nodejs environment'); }

export default getAbsoluteFSPath

by removing the line return require("path").resolve(__dirname) it solve the issue . any other possible fix for that please?

Mehdi-MST avatar Apr 22 '24 08:04 Mehdi-MST

I am using the lastest version 5.17.2 and also the version with angular 17

Mehdi-MST avatar Apr 22 '24 08:04 Mehdi-MST

using try catch solved the issue const getAbsoluteFSPath = function () { // detect whether we are running in a browser or nodejs if (typeof module !== "undefined" && module.exports) { try { return require("path").resolve(__dirname) } catch (e) { throw new Error('Unable to determine the current working directory') } } }

export default getAbsoluteFSPath

Mehdi-MST avatar Apr 26 '24 09:04 Mehdi-MST

I have the same issue, anyone?

@Mehdi-MST Are you using Angular 18 SSR too? It's unbelievably broken, don't the Angular team test their framework?

samerkassem82 avatar Jul 19 '24 15:07 samerkassem82

Yes I use angular. Doesnt matter ssr or not on build I get that error. Temporary fix it comment that line and everything works fine

Mehdi-MST avatar Jul 19 '24 15:07 Mehdi-MST

@Mehdi-MST For me it wasn't resolved , when I commented it

/*
 * getAbsoluteFSPath
 * @return {string} When run in NodeJS env, returns the absolute path to the current directory
 *                  When run outside of NodeJS, will return an error message
 */
const getAbsoluteFSPath = function () {
  // detect whether we are running in a browser or nodejs
  if (typeof module !== "undefined" && module.exports) {
   // return require("path").resolve(__dirname)
  }
  throw new Error('getAbsoluteFSPath can only be called within a Nodejs environment');
}

module.exports = getAbsoluteFSPath

I got Error: getAbsoluteFSPath can only be called within a Nodejs environment

samerkassem82 avatar Jul 19 '24 15:07 samerkassem82

When you comment out that line and run build that should solve the issue. But whenever you run npm i that overwrite that line again. So that doesnt help if you are using automation builder

Sent from Outlook for Androidhttps://aka.ms/AAb9ysg


From: Samer @.> Sent: Friday, July 19, 2024 4:36:49 PM To: swagger-api/swagger-ui @.> Cc: Mehdi Mahmud @.>; Mention @.> Subject: Re: [swagger-api/swagger-ui] ANgular build require Path on build (Issue #9856)

@Mehdi-MSThttps://github.com/Mehdi-MST For me it wasn't resolved , when I commented it

/*

  • getAbsoluteFSPath
  • @return {string} When run in NodeJS env, returns the absolute path to the current directory
  •              When run outside of NodeJS, will return an error message
    

*/ const getAbsoluteFSPath = function () { // detect whether we are running in a browser or nodejs if (typeof module !== "undefined" && module.exports) { // return require("path").resolve(__dirname) } throw new Error('getAbsoluteFSPath can only be called within a Nodejs environment'); }

module.exports = getAbsoluteFSPath

I got Error: getAbsoluteFSPath can only be called within a Nodejs environment

— Reply to this email directly, view it on GitHubhttps://github.com/swagger-api/swagger-ui/issues/9856#issuecomment-2239475727, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AXYITB4OUWWS36WLKA6VYN3ZNEXBDAVCNFSM6AAAAABGSJPRT2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZZGQ3TKNZSG4. You are receiving this because you were mentioned.Message ID: @.***>

Mehdi-MST avatar Jul 19 '24 15:07 Mehdi-MST