Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Zero-byte in output #96

Closed
StreetStrider opened this issue Sep 7, 2017 · 4 comments · Fixed by #124
Closed

Zero-byte in output #96

StreetStrider opened this issue Sep 7, 2017 · 4 comments · Fixed by #124

Comments

@StreetStrider
Copy link

Hello, I'm experimenting with this plugin, and trying to achieve smooth experience both for frontend and backend builds.

For now I got pretty simple setup for «backend»:

return rollup(
{
	entry: entry, // '.ts' file
	external: id => id !== entry, // mark everything as external
	plugins: ts(
	{
		typescript: require('typescript')
	}),
})
.then(bundle =>
{
	return bundle.generate(
	{
		format:  'cjs',
		exports: 'auto',
	})
})

Somehow NUL-byte is inserted inside require('typescript-helpers');.
I see '\'use strict\';\n\nrequire(\'\u0000typescript-helpers\');\n… when I debug output.
What on earth could cause this weird insertion to happen?

@StreetStrider
Copy link
Author

I believe this happens when typescript-helpers are marked as external. I got similar build but with dependencies bundled (for frontend target) and it bundles just ok.

@StreetStrider
Copy link
Author

This is not a critical, cause I just replace zero-byte with empty string, but definitely it would be interesting to track this down.
@Rich-Harris

@StreetStrider
Copy link
Author

Actually, I found this is done by intent. 🤔

// The injected id for helpers. Intentially invalid to prevent helpers being included in source maps.
const helpersId = '\0typescript-helpers';

Maybe this works in frontend bundles, but when the target is cjs/node it leads to corruption of every file which includes typescript-helpers which means, every file. Is it an ugly workaround?

@stakx
Copy link

stakx commented Aug 1, 2018

Yes, this is intentional, and probably done because of what Rollup's documentation recommends to plugin authors in https://github.com/rollup/rollup/wiki/Plugins#conventions:

If your plugin uses 'virtual modules' (e.g. for helper functions), prefix the module ID with \0. This prevents other plugins from trying to process it.

Replacing this plugin's own helper functions with ts-lib and --importHelpers would get rid of that "virtual module" and the NUL character.

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

Successfully merging a pull request may close this issue.

2 participants