Using third-party node modules with Excel JS Add-In

Eric Levy 6 Reputation points
2022-11-30T15:12:27.99+00:00

I am trying to create an Excel plug-in to generate custom functions (aka UDFs) to pull data from a web data source that uses a OAUTH1 Three-Step process to gather the data. It's similar to an OAUTH2 process, but can connect to the localhost.

I have code that can run on Node.JS to authorize the OUATH1 process. It uses the following code:

var papaParse = require('papaparse');
const express = require("express");
const {nanoid} = require("nanoid");
const open = require("open");
const crypto = require('crypto');
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));

Does the Excel plugin run in the browser space and thus doesn't have access to express?

I am not sure I understand how I can potentially use these libraries within an Excel Add-In project. In a worse case scenerio, I can require the user to plugin tokens and remove the requirement for express, but I will still need the other libraries.

I added each library to the project using "npm install papaparse", "npm install express", etc.

Below are the errors I am receiving with the above libraries in the code.

WARNING in ./node_modules/express/lib/view.js 81:13-25
Critical dependency: the request of a dependency is an expression
@ ./node_modules/express/lib/application.js 22:11-28
@ ./node_modules/express/lib/express.js 18:12-36
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

WARNING in ./node_modules/on-finished/index.js 207:11-33
Module not found: Error: Can't resolve 'async_hooks' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\on-finished'
@ ./node_modules/express/lib/response.js 23:17-39
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

WARNING in ./node_modules/raw-body/index.js 302:11-33
Module not found: Error: Can't resolve 'async_hooks' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\raw-body'
@ ./node_modules/body-parser/lib/read.js 16:14-33
@ ./node_modules/body-parser/lib/types/raw.js 15:11-29
@ ./node_modules/body-parser/index.js 144:15-41
@ ./node_modules/express/lib/express.js 15:17-39
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

3 warnings have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

ERROR in ./src/functions/functions.js 56:13-30
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\src\functions'

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: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }

ERROR in ./node_modules/body-parser/lib/read.js 20:11-26
Module not found: Error: Can't resolve 'zlib' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\body-parser\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: { "zlib": require.resolve("browserify-zlib") }'
- install 'browserify-zlib'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "zlib": false }
@ ./node_modules/body-parser/lib/types/raw.js 15:11-29
@ ./node_modules/body-parser/index.js 144:15-41
@ ./node_modules/express/lib/express.js 15:17-39
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/body-parser/lib/types/urlencoded.js 228:12-34
Module not found: Error: Can't resolve 'querystring' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\body-parser\lib\types'

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: { "querystring": require.resolve("querystring-es3") }'
- install 'querystring-es3'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "querystring": false }
@ ./node_modules/body-parser/index.js 150:15-48
@ ./node_modules/express/lib/express.js 15:17-39
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/cookie-signature/index.js 5:13-30
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\cookie-signature'

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: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }
@ ./node_modules/express/lib/response.js 27:11-43
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/destroy/index.js 16:17-41
Module not found: Error: Can't resolve 'fs' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\destroy'
@ ./node_modules/send/index.js 18:14-32
@ ./node_modules/express/lib/response.js 32:11-26
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/destroy/index.js 17:13-30
Module not found: Error: Can't resolve 'stream' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\destroy'

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: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
@ ./node_modules/send/index.js 18:14-32
@ ./node_modules/express/lib/response.js 32:11-26
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/destroy/index.js 18:11-26
Module not found: Error: Can't resolve 'zlib' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\destroy'
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: { "zlib": require.resolve("browserify-zlib") }'
- install 'browserify-zlib'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "zlib": false }
@ ./node_modules/send/index.js 18:14-32
@ ./node_modules/express/lib/response.js 32:11-26
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/etag/index.js 21:13-30
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\etag'

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: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }
@ ./node_modules/express/lib/utils.js 21:11-26
@ ./node_modules/express/lib/application.js 24:18-48 25:25-62 26:19-50
@ ./node_modules/express/lib/express.js 18:12-36
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/etag/index.js 22:12-31
Module not found: Error: Can't resolve 'fs' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\etag'
@ ./node_modules/express/lib/utils.js 21:11-26
@ ./node_modules/express/lib/application.js 24:18-48 25:25-62 26:19-50
@ ./node_modules/express/lib/express.js 18:12-36
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/express/lib/application.js 23:11-26
Module not found: Error: Can't resolve 'http' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\express\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/express/lib/express.js 18:12-36
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/express/lib/request.js 18:11-30
Module not found: Error: Can't resolve 'net' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\express\lib'
@ ./node_modules/express/lib/express.js 21:10-30
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/express/lib/request.js 20:11-26
Module not found: Error: Can't resolve 'http' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\express\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/express/lib/express.js 21:10-30
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/express/lib/response.js 21:11-26
Module not found: Error: Can't resolve 'http' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\express\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/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/express/lib/utils.js 24:18-40
Module not found: Error: Can't resolve 'querystring' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\express\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: { "querystring": require.resolve("querystring-es3") }'
- install 'querystring-es3'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "querystring": false }
@ ./node_modules/express/lib/application.js 24:18-48 25:25-62 26:19-50
@ ./node_modules/express/lib/express.js 18:12-36
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/express/lib/view.js 18:9-22
Module not found: Error: Can't resolve 'fs' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\express\lib'
@ ./node_modules/express/lib/application.js 22:11-28
@ ./node_modules/express/lib/express.js 18:12-36
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/is-docker/index.js 2:11-24
Module not found: Error: Can't resolve 'fs' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\is-docker' @ ./node_modules/open/index.js 5:17-37
@ ./src/functions/functions.js 54:11-26

ERROR in ./node_modules/is-wsl/index.js 2:11-24
Module not found: Error: Can't resolve 'os' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\is-wsl'

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: { "os": require.resolve("os-browserify/browser") }'
- install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "os": false }
@ ./node_modules/open/index.js 4:14-31
@ ./src/functions/functions.js 54:11-26

ERROR in ./node_modules/is-wsl/index.js 3:11-24
Module not found: Error: Can't resolve 'fs' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\is-wsl'
@ ./node_modules/open/index.js 4:14-31
@ ./src/functions/functions.js 54:11-26

ERROR in ./node_modules/mime/mime.js 2:9-22
Module not found: Error: Can't resolve 'fs' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\mime'
@ ./node_modules/send/index.js 24:11-26
@ ./node_modules/express/lib/response.js 32:11-26
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/open/index.js 2:21-45
Module not found: Error: Can't resolve 'child_process' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\open'
@ ./src/functions/functions.js 54:11-26

ERROR in ./node_modules/open/index.js 3:47-60
Module not found: Error: Can't resolve 'fs' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\open'
@ ./src/functions/functions.js 54:11-26

ERROR in ./node_modules/parseurl/index.js 15:10-24
Module not found: Error: Can't resolve 'url' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\parseurl'
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: { "url": require.resolve("url/") }'
- install 'url'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "url": false }
@ ./node_modules/express/lib/request.js 23:12-31
@ ./node_modules/express/lib/express.js 21:10-30
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/send/index.js 23:9-22
Module not found: Error: Can't resolve 'fs' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\send'
@ ./node_modules/express/lib/response.js 32:11-26
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/send/index.js 30:13-30
Module not found: Error: Can't resolve 'stream' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\send'

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: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
@ ./node_modules/express/lib/response.js 32:11-26
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

ERROR in ./node_modules/serve-static/index.js 21:10-24
Module not found: Error: Can't resolve 'url' in 'C:\Users\EricLevy\OneDrive - Meridian Business Services\mb_ns_connector_test\mb_ns_connector_test\node_modules\serve-static'

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: { "url": require.resolve("url/") }'
- install 'url'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "url": false }
@ ./node_modules/express/lib/express.js 81:0-40
@ ./node_modules/express/index.js 11:0-41
@ ./src/functions/functions.js 49:14-32

25 errors have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

Microsoft 365 and Office Development Office JavaScript API
Microsoft 365 and Office Development Other
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. David Chesnut 166 Reputation points Microsoft Employee
    2022-12-01T17:48:24.967+00:00

    Hi @Eric Levy ,

    Yes, the custom functions run in a JS-only runtime by default. They won't have access to the DOM and typical browser features you might expect. In this case you should switch the project to a shared runtime as explained in this article. This will get the custom functions to run in the same webview as the task pane and they will have full access to browser features such as the DOM.

    Hope this helps,
    David

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.