script-lab icon indicating copy to clipboard operation
script-lab copied to clipboard

Making importing any libraries easier (original title: "'require' is not defined")

Open gergzk opened this issue 7 years ago • 7 comments

Bug Report

  • Host: Excel win32
  • OS: Win10
  • Browser:
  • Environment: react alpha

Expected behavior:

I shuold be able to import an npm package that uses 'require'

Actual behavior:

'require' is not defined,https://unpkg.com/[email protected]/url.js,24,1,ReferenceError: 'require' is not defined

Steps to Reproduce:

Create a new sample in SL. Add 'url' in imports (this points to https://www.npmjs.com/package/url) import * as url from 'url' in the source code Run Above error appears.

gergzk avatar Dec 20 '18 05:12 gergzk

I believe this is correct behavior? require isn't available in the web as it is in node. image

nico-bellante avatar Dec 20 '18 07:12 nico-bellante

So does that mean I can't pick up that package in ScriptLab then? That's annoying … and as a user I won't really understand which packages will/won't work.

On Wed, Dec 19, 2018 at 11:08 PM nico-bellante [email protected] wrote:

I believe this is correct behavior? require isn't available in the web as it is in node. [image: image] https://user-images.githubusercontent.com/35939126/50269393-fb974d80-03e2-11e9-8ab5-e2934ea7464c.png

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/OfficeDev/script-lab-react/issues/482#issuecomment-448896523, or mute the thread https://github.com/notifications/unsubscribe-auth/AXsyQVHM3iwvwPKPRJNPTdrbc5uz-NsJks5u6zdygaJpZM4Zbg89 .

gergzk avatar Dec 20 '18 07:12 gergzk

@gergzk , see the log description I once wrote (that admittedly we never merged, mostly because it wasn't clear where exactly to document it, and no one else other than me had run into it at that point).

https://github.com/OfficeDev/script-lab/pull/391/files#diff-04c6e90faac2675aa89e2176d2eec7d8R99

Do you think it's worth resurrecting this text and putting it somewhere? Where?

Zlatkovsky avatar Dec 24 '18 19:12 Zlatkovsky

Yikes, that is a lot of text to navigate .... @peronald - how do we think about the relationship between those who use packages and those who are able to navigate the instructions needed to make some packages work? There's also a related question of if we should include a few popular/useful oss packages by default.

gergzk avatar Dec 25 '18 05:12 gergzk

Alternatively, we could invest into looking into doing weback on the fly, doing compilation just as you would in VS Code + TS + webpack -- which would allow us to support both distributed-for-web as well regular NPM packages (incl. "import" and "require" syntax), and also with a side-benefit of accruing towards supporting Fabric React (for the pro-dev playground scenario)

Zlatkovsky avatar Dec 25 '18 13:12 Zlatkovsky

How can I use npm packages like request-promise or fs without these ? I tried on the libraries panel @types/request-promise @types/fs

But how can I reference them on the Script panel ?

iabukai avatar Jun 28 '19 13:06 iabukai

@iabukai, for libraries to work with Script Lab, they need to be ideally already pre-compiled for the browser. See more on https://github.com/OfficeDev/script-lab-2017/pull/391/files#diff-04c6e90faac2675aa89e2176d2eec7d8R99

Zlatkovsky avatar Jun 28 '19 17:06 Zlatkovsky

Use of libraries is an edge case for Script Lab. Script Lab is for customers to play with office.js APIs

If customers need to use libraries they should build a full Add-In.

Customers can create and host their own Add-In on GitHub, for example see the Build Add-In you can sideload the manifest.

wandyezj avatar Apr 04 '24 20:04 wandyezj