I'm trying to resolve some SSL issues w/ Axios in my Office Add-In which is using NPM and WebPack. All the answers I see online I believe relate to running a NodeJS server on the backend, but this is client side.
I've been reading the following SO post --> How to configure axios to use SSL certificate?
But when I add this to my .js I get tons of errors during webpack build and then I get https is undefined errors in console.
const httpsAgent = require('https-agent')
const https = require('https')
Here are the errors, is this only something that can be done in a NodeJS Server, I believe my setup is considered a client side app, but I'm new to Office JS and a few of these technologies. How can I manipulate the https settings? Axios does work in my setup, I just can't seem to manipulate the SSL verification settings.
Module not found: Error: Can't resolve 'https' in 'C:\Users\USERNAME\odev\ExcelWebAddIn1Web\yo\src\commands'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
- install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "https": false }
ERROR in ./node_modules/https-agent/index.js 1:12-28
Module not found: Error: Can't resolve 'https' in 'C:\Users\USERNAME\odev\ExcelWebAddIn1Web\yo\node_modules\https-agent'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
- install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "https": false }
@ ./src/commands/commands.js 21:17-39
ERROR in ./node_modules/tunnel/lib/tunnel.js 3:10-24
Module not found: Error: Can't resolve 'net' in 'C:\Users\USERNAME\odev\ExcelWebAddIn1Web\yo\node_modules\tunnel\lib'
@ ./node_modules/tunnel/index.js 1:0-40
@ ./node_modules/https-agent/index.js 2:13-30
@ ./src/commands/commands.js 21:17-39
ERROR in ./node_modules/tunnel/lib/tunnel.js 4:10-24
Module not found: Error: Can't resolve 'tls' in 'C:\Users\USERNAME\odev\ExcelWebAddIn1Web\yo\node_modules\tunnel\lib'
@ ./node_modules/tunnel/index.js 1:0-40
@ ./node_modules/https-agent/index.js 2:13-30
@ ./src/commands/commands.js 21:17-39
ERROR in ./node_modules/tunnel/lib/tunnel.js 5:11-26
Module not found: Error: Can't resolve 'http' in 'C:\Users\USERNAME\odev\ExcelWebAddIn1Web\yo\node_modules\tunnel\lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
- install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "http": false }
@ ./node_modules/tunnel/index.js 1:0-40
@ ./node_modules/https-agent/index.js 2:13-30
@ ./src/commands/commands.js 21:17-39
ERROR in ./node_modules/tunnel/lib/tunnel.js 6:12-28
Module not found: Error: Can't resolve 'https' in 'C:\Users\USERNAME\odev\ExcelWebAddIn1Web\yo\node_modules\tunnel\lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
- install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "https": false }
@ ./node_modules/tunnel/index.js 1:0-40
@ ./node_modules/https-agent/index.js 2:13-30
@ ./src/commands/commands.js 21:17-39
6 errors have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.
webpack 5.53.0 compiled with 6 errors in 5648 ms
C:\Users\USERNAME\odev\ExcelWebAddIn1Web\yo>
Update:
I have found a few things, not sure whats doing what and I have trouble reproducing error after I open the URL, I think at the moment I have disabled SSL verification successfully, but I'd prefer to use the CA vs disable SSL.
I added the following to Webpack:
const Dotenv = require('dotenv-webpack');
new Dotenv(),
...
https: env.NODE_TLS_REJECT_UNAUTHORIZED = 0,
I saw this in Webpack which makes me thing I need to configure my https.Agent outside JS.
async function getHttpsOptions() {
const httpsOptions = await devCerts.getHttpsServerOptions();
return { cacert: httpsOptions.ca, key: httpsOptions.key, cert: httpsOptions.cert };
}