hydrogen icon indicating copy to clipboard operation
hydrogen copied to clipboard

[Error message] - [vite] Internal server error: `line` must be greater than 0 (lines start at line 1)

Open davecyen opened this issue 3 years ago • 1 comments

Describe the bug This is not a bug, but a request for a more specific and clearer error message.

In vite.config.js, if I include an optimizeDeps package that I've removed from my project, or that I haven't installed, then I get a non-descriptive error message.

optimizeDeps: {include: ['...']},

Instead, the error message should let me know to check the dependencies referenced in vite.config.js.

Screen Shot 2022-05-26 at 12 49 15 PM

davecyen avatar May 26 '22 19:05 davecyen

I am getting this vague error message as well. Seems like there's something going wrong while rewriting the stack trace. Possibly related to this offset variable in the code below. I am using Node v16.17.0.

let offset;
try {
    new Function('throw new Error(1)')();
}
catch (e) {
    // in Node 12, stack traces account for the function wrapper.
    // in Node 13 and later, the function wrapper adds two lines,
    // which must be subtracted to generate a valid mapping
    const match = /:(\d+):\d+\)$/.exec(e.stack.split('\n')[1]);
    offset = match ? +match[1] - 1 : 0;
}
function ssrRewriteStacktrace(stack, moduleGraph) {
    return stack
        .split('\n')
        .map((line) => {
        return line.replace(/^ {4}at (?:(.+?)\s+\()?(?:(.+?):(\d+)(?::(\d+))?)\)?/, (input, varName, url, line, column) => {
            var _a;
            if (!url)
                return input;
            const mod = moduleGraph.urlToModuleMap.get(url);
            const rawSourceMap = (_a = mod === null || mod === void 0 ? void 0 : mod.ssrTransformResult) === null || _a === void 0 ? void 0 : _a.map;
            if (!rawSourceMap) {
                return input;
            }
            const traced = new TraceMap(rawSourceMap);
            const pos = originalPositionFor$1(traced, {
                line: Number(line) - offset,
                column: Number(column)
            });
            if (!pos.source || pos.line == null || pos.column == null) {
                return input;
            }
            const source = `${pos.source}:${pos.line}:${pos.column}`;
            if (!varName || varName === 'eval') {
                return `    at ${source}`;
            }
            else {
                return `    at ${varName} (${source})`;
            }
        });
    })
        .join('\n');
}

For me, removing optimizeDeps in vite.config.js has no impact at all. I've tried forcing the offset to be a minimum value of 1, then I get to see the "real" error I think, which is require is not defined in node_modules/prop-types/index.js.

dduupp avatar Aug 17 '22 11:08 dduupp