Skip to content
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

sourceURL contains null-character at the beginning #145

Open
derolf opened this issue Sep 15, 2020 · 6 comments
Open

sourceURL contains null-character at the beginning #145

derolf opened this issue Sep 15, 2020 · 6 comments

Comments

@derolf
Copy link

derolf commented Sep 15, 2020

I am having a very weird. Some of the sourceURL references in my nolluped files contain a null-character at the beginning. Example:

//# sourceURL=<null-character-here>commonjsHelpers.js');

I was tracing the problem at least up to this position in PluginLifecycle.js:

        async resolveId (context, id, parentFilePath) {
            let hr = await callAsyncFirstHook(context, 'resolveId', [id, parentFilePath]);

            if (hr === false) {
                return false;
            }


            if (typeof hr === 'string') {
                if (hr[0] === '\000') {
                    throw Error(`"${hr}" contains a null-character at the beginning. encodeURI yields: ${encodeURI(hr)}`);
                }

With this debug code, I get this on the console:

[Nollup] Listening on http://localhost:8081
Error: "commonjsHelpers.js" contains a null-character at the beginning. encodeURI yields: %00commonjsHelpers.js
    at Object.resolveId (/Users/darolf/dev/superapp/node_modules/nollup/lib/impl/PluginLifecycle.js:138:27)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Since I am lost in the details how plugin/hooks get called by nollup, I don't know how to trace this to the source problem.

Any idea how this can happen???

@PepsRyuu
Copy link
Owner

The CommonJS plugin likely includes the \0 null byte at the beginning to prevent other plugins from trying to process the helper files as an optimisation and to prevent a loop internally.

Is it causing any build failures or something to break?

@derolf
Copy link
Author

derolf commented Sep 15, 2020

Yeah, I am loading the file through a C++ layer into JavaScriptCore. It broke when the C++ standard library terminated the string at the 0-character. The error message was SyntaxError: Unexpected EOF or something...

I created a unit-test and once I removed all 0-characters, the test passed.

@PepsRyuu
Copy link
Owner

...That's a new one, sounds interesting! The fix wouldn't be hard anyways, just a matter of determining where in Nollup to filter out the \0. Can probably release something for this shortly.

@derolf
Copy link
Author

derolf commented Sep 15, 2020

I can confirm that after removing null-characters also the "live app" works!

@PepsRyuu
Copy link
Owner

#146 This should hopefully take care of it. If you could give it a try and confirm, it'd be much appreciated! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants