Making importing any libraries easier (original title: "'require' is not defined")
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.
I believe this is correct behavior? require isn't available in the web as it is in node.

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 , 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?
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.
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)
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, 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
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.