-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Angular CLI: VM package and process from node.js not available when targeting the browser (compile error) #135
Comments
As i have been testing i found a way to run it without "errors" but i did need to do some changes to the lib. All of this should be easily fixable but splitting nodejs and browser user access points properly. To avoid the "vm" not found error we can create a empty file and add it to the
After this we get a To fix this one we actually need to change the files
change to
|
Hi, I think you make a great point. Just to be sure, which version of docx-templates are you using? The I think we need to:
|
Hello I am using the last version from NPM published today 4.2.0. Totally agree nowadays is a bit tricky to implement a solution compatible with all the solutions used to transpile/build js. Aside from the changes i just pointed above, it is just import and use normally. I can try and put together a PR with the changes required to fix these problems. If you want me to. Once again thanks a lot great job |
…presence of process.env outside of test code. Related to #135.
Ok, clear! I've removed the DEBUG flag. I'm also working on an Angular example to add to the I'll check if I can make a few changes to how |
Hi Thats great apart from the Otherwise the trick that i mentioned should work for any typescript project (not only angular). It just points the "vm" lib to a empty file making the compile be able to find it. It is not used in runtime anyway at least if you set I would recommend to split the system into two methods one that uses require("vm") and other stuff from node to speed thing up and a second method using only browser available method. Check this article out https://dev.to/riversun/recipes-on-how-to-create-a-library-that-supports-both-browser-and-node-js-201m should help with this. There is also another option, you can build the library twice. One build using browserify that automatically translates nodejs stuff to browser compatible code. And a second time as is for node.js. Once again thanks a lot! |
Alright, i've done some more digging. It seems that besides Both these Node APIs are apparently cleanly shimmed by browserify/webpack. I didn't know the Angular CLI did so little magic in comparison... Hence, I think distributing a separate browserify build is the only way to thoroughly tackle this and make good on our 'browser compatible' promises. That should also allow users to use the whole thing without a transpiler. |
I'm currently deeply in JS toolchain hell. I've transpiled the library using browserify and tsify and made a browser entrypoint (see the browserify-browser-build branch). I'm testing whether importing the lib works in example-angularcli, but i'm getting an error. Note that angular app compilation succeeds: it is a runtime error. Would appreciate it if you could take a look. |
Sure, i will create a branch to test it and check the runtime error. To see if i'm able to figure our a way fix it somehow. Thanks a lot! |
Well, got the error to go away but the shim introduced by browserify for stream doesnt seem to be working. Probably and for now removing the DEBUG should be enough for it to work without any major configuration. I will try during the weekend to come up with a better solution to this. Thanks a lot! |
Closing this because resolving this is nontrivial and very specific to the angular toolchain. Feel free to reopen if you have a fix. |
https://github.com/guigrpa/docx-templates/releases/tag/v4.8.0 may help with this. |
@jjhbw here I am facing the same issue with angular 12 webpack 5. It seems Webpack 5 does not polyfill the node libs automatically like webpack 4 was doing. Since the sandboxjs library has It can be solved by installing vm-browserfy as dev dependency and adding the path from But I guess in some point it should be marked as peerDependency in order to notify about this during the installation. |
You can also use the browser-ready-bundle see https://github.com/guigrpa/docx-templates#polyfilled-browser-ready-bundle this includes vm-browserfy. BUT if you do the report-generation in a worker you don't block the Main-Thread and you can (also need to as vm-browserfy doesn't work in a worker) disable the sandbox (so no vm package needed). |
Hello
When using the library inside of a typescript based project (in my case Angular) the vm library from nodejs cannot be found by the compiler.
The JS sandbox environment relies on this package to work. On the browser (unless using browserify with the browser-vm package) there is no way to get the code "compiling" properly, (at least if you compiler tries to solve every lib imported).
This could be solved if a method that does not rely on the vm lib was introduced in the lib.
Thanks a lot for working on this project.
Cheers
The text was updated successfully, but these errors were encountered: