Skip to content

Fatal error: Cannot overwrite a zero-length range – use appendLeft or prependRight instead #41

@Richard-Walton

Description

@Richard-Walton

I've recently upgraded my brfs package to 1.50 which includes the latest source map changes implemented in this module.

Unfortunately my build is now failing with the following error:

Fatal error: Cannot overwrite a zero-length range – use appendLeft or prependRight instead

After some digging around I tracked down the issue to this line:
https://github.com/browserify/static-module/blob/master/index.js#L64

In my case s.offset === 0 (creating the aforementioned zero-length range error).

I have discovered a workaround for the issue. Originally my code looked like this:

var fs = require('fs')
    , anotherModule = require('anotherModule')
    , x = true;
...
var file = fs.readFileSync(....);

Moving the require('fs') to it's own line fixes the problem:

var fs = require('fs');
var anotherModule = require('anotherModule')
    , x = true;
...
var file = fs.readFileSync(....);

I wonder if the removal of the require('fs') calls during the browserify build process causes this error?

My initial thoughts to fix this issue would involve adding a guard against s.offset being 0... I'm happy to open a PR if you think this is a viable solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions