简体   繁体   中英

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

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 and expected to be able to access these libraries and use them in the project.

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'`

An Office web add-in is run in a web browser (embedded). So, you may consider it as a client application where ExpressJS doesn't make any sense. ExpressJS is used on the server-side instead (for example, to create APIs).

An Excel Add-in is a web application, so it has both a server-side and a client-side. An express server runs in Node.js on the server side. Any libraries that can be used in Node.js can be used in an Excel Add-in too.

The errors in your question don't have anything to do with the fact that you will be surfacing your web application as an Excel Add-in. Consider editing your question and title (and tags) to remove mention of the add-in. Node.js and express experts might ignore the question if they think it is about Excel Add-ins.

I would suggest that you get your web application working in a browser first. Just leave out the JavaScript that calls Office.js.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM