twig.js icon indicating copy to clipboard operation
twig.js copied to clipboard

require() triggers a warning if running in browser

Open tacman opened this issue 2 years ago • 6 comments

There is a warning in then console about the require function not being present when running twigjs as an imported module.

Please see https://github.com/symfony/symfony/discussions/52252#

The code still works, but it would be nice to get rid of this warning.

tacman avatar Oct 23 '23 18:10 tacman

Looks like the loader could use some tweaks to have it function better with the browser: https://github.com/twigjs/twig.js/blob/master/src/twig.loader.fs.js#L9

RobLoach avatar Nov 06 '23 19:11 RobLoach

I used to have something in place when I used webpack to avoid the error, but I don't know if it will work with modules. What is fs, and is there a package on jsdelivr that can be used for it?

tacman avatar Nov 06 '23 19:11 tacman

In what context is the fs loader being used in the browser? Wouldn't you use a different loader in that case?

willrowe avatar Nov 07 '23 14:11 willrowe

as a module. See the js console at https://jsfiddle.net/tacman1123/azb4dmwe/7/

On Tue, Nov 7, 2023 at 9:41 AM Will Rowe @.***> wrote:

In what context is the fs loader being used in the browser? Wouldn't you use a different loader in that case?

— Reply to this email directly, view it on GitHub https://github.com/twigjs/twig.js/issues/880#issuecomment-1798687240, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEXIQN3HJS5CGJVD5OEO73YDJCB3AVCNFSM6AAAAAA6MQ3LFCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJYGY4DOMRUGA . You are receiving this because you authored the thread.Message ID: @.***>

tacman avatar Nov 07 '23 19:11 tacman

Interesting, so it happens just by importing without doing anything else?

willrowe avatar Nov 07 '23 19:11 willrowe

yes. But fortunately it works (beautifully). The code is wrapping in a try / catch, but still throws the warning.

On Tue, Nov 7, 2023 at 2:29 PM Will Rowe @.***> wrote:

Interesting, so it happens just by importing without doing anything else?

— Reply to this email directly, view it on GitHub https://github.com/twigjs/twig.js/issues/880#issuecomment-1799759098, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEXIQOOYHAN5VPKZHBJTRDYDKD3JAVCNFSM6AAAAAA6MQ3LFCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJZG42TSMBZHA . You are receiving this because you authored the thread.Message ID: @.***>

tacman avatar Nov 07 '23 19:11 tacman