Sapper: UnhandledPromiseRejectionWarning: Unhandled promise rejection with sapper.dist.core

Created on 9 Oct 2019  路  16Comments  路  Source: sveltejs/sapper

I love Svelte and I am eager to use Sapper, particularly to compare it to Python's Django framework. However, I'm encountering an issue out of the gate when following the Getting Started instructions from the main website. After I run npx degit "sveltejs/sapper-template#rollup" [app-name] and after I cd into the app directory, I get this:

C:\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir>npm install
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

added 231 packages from 173 contributors and audited 1592 packages in 35.781s
found 0 vulnerabilities


C:\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir>npm run dev

> [email protected] dev C:\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir
> sapper dev

(node:15452) UnhandledPromiseRejectionWarning: D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\rollup.config.js:1
import resolve from 'rollup-plugin-node-resolve';
       ^^^^^^^

SyntaxError: Unexpected identifier
    at Module._compile (internal/modules/cjs/loader.js:721:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Object.require.extensions..js (D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\node_modules\sapper\dist\core.js:883:5)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Function.load_config (D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\node_modules\sapper\dist\core.js:887:18)
(node:15452) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:15452) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The line and cursor values point to the async load_config function within the RollUp class object. I would imagine that the catching functionality would be inherited from somewhere so I'm not sure why this code is causing the error.

    static async load_config(cwd) {
        if (!rollup) rollup = requireRelative_1('rollup', cwd);

        const input = path.resolve(cwd, 'rollup.config.js');

        const bundle = await rollup.rollup({
            input,
            inlineDynamicImports: true,
            external: (id) => {
                return (id[0] !== '.' && !path.isAbsolute(id)) || id.slice(-5, id.length) === '.json';
            }
        });

        const resp = await bundle.generate({ format: 'cjs' });
        const { code } = resp.output ? resp.output[0] : resp;

        // temporarily override require
        const defaultLoader = require.extensions['.js'];
        require.extensions['.js'] = (module, filename) => {
            if (filename === input) {
                module._compile(code, filename);
            } else {
                defaultLoader(module, filename);
            }
        };

        const config = require(input);
        delete require.cache[input];

        return config;
    }

All 16 comments

This is a really weird error. What version of Node are you on? Svelte and Sapper require at least 8.

Oh, I'm on 6.12. That could be why. Let me update and report back.

Pardon, npm was at v6.12. I am on Node v10 but I'm currently upgrading to 12.

Okay, the problem persists after upgrading Node to v12.

C:\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir>npm run dev

> [email protected] dev C:\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir
> sapper dev

(node:22372) UnhandledPromiseRejectionWarning: D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\rollup.config.js:1
import resolve from 'rollup-plugin-node-resolve';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Module._compile (internal/modules/cjs/loader.js:881:18)
    at Module._extensions..js (internal/modules/cjs/loader.js:962:10)
    at Object.require.extensions..js (D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\node_modules\sapper\dist\core.js:883:5)
    at Module.load (internal/modules/cjs/loader.js:798:32)
    at Function.Module._load (internal/modules/cjs/loader.js:711:12)
    at Module.require (internal/modules/cjs/loader.js:838:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Function.load_config (D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\node_modules\sapper\dist\core.js:887:18)
    at async Object.create_compilers (D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\node_modules\sapper\dist\core.js:1118:18)
    at async Watcher.init (D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\node_modules\sapper\dist\dev.js:215:21)
(node:22372) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:22372) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I suspect this has something to do with file path differences on windows vs unix, but I can't reproduce this on windows either.

Can you open up node_modules/sapper/dist/core.js around line 880 and make this change:

        // temporarily override require
        const defaultLoader = require.extensions['.js'];
        require.extensions['.js'] = (module, filename) => {
            console.log(filename, input); // ADD THIS LINE
            if (filename === input) {
                module._compile(code, filename);
            } else {
                defaultLoader(module, filename);
            }
        };

and re-run npm run dev and paste your output?

D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\rollup.config.js C:\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\rollup.config.js
(node:18120) UnhandledPromiseRejectionWarning: D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\rollup.config.js:1
import resolve from 'rollup-plugin-node-resolve';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Module._compile (internal/modules/cjs/loader.js:881:18)
    at Module._extensions..js (internal/modules/cjs/loader.js:962:10)
    at Object.require.extensions..js (D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\node_modules\sapper\dist\core.js:884:5)
    at Module.load (internal/modules/cjs/loader.js:798:32)
    at Function.Module._load (internal/modules/cjs/loader.js:711:12)
    at Module.require (internal/modules/cjs/loader.js:838:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Function.load_config (D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\node_modules\sapper\dist\core.js:888:18)
    at async Object.create_compilers (D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\node_modules\sapper\dist\core.js:1119:18)
    at async Watcher.init (D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\node_modules\sapper\dist\dev.js:215:21)
(node:18120) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:18120) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

noted line of code from sapper\dist\dev.js:215:21:

        const compilers = await core.create_compilers(this.bundler, cwd, src, dest, true);

Do you have something unusual going on with your C: drive and your D: drive? Which path do these files actually live at? I see that you're running from C:\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir but the stack traces all mention D:\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir.

Can you try making this change as well? I'm hoping this will work around whatever's happening on your machine, but I'd still like to try to get to the bottom of it if possible.

        // temporarily override require
        const defaultLoader = require.extensions['.js'];
        require.extensions['.js'] = (module, filename) => {
            require.extensions['.js'] = defaultLoader;
            module._compile(code, filename);
        };

ohhh, I am using mklinks, which I guess can be the culprit? I haven't encountered this with Python or other languages, so this never occurred to me. Let me check.

Resolved! The issue seems to stem from mklinks. A cursory search seems to suggest that this is a common issue involving node.

https://github.com/gulpjs/vinyl-fs/issues/210

Can you try the change in my last comment though to see if that lets you run this while still using symlinks?

Oh, sure thing. One sec.

It doesn't work. The stdout:

D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\rollup.config.js C:\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\rollup.config.js
(node:19296) UnhandledPromiseRejectionWarning: D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\rollup.config.js:1
import resolve from 'rollup-plugin-node-resolve';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Module._compile (internal/modules/cjs/loader.js:881:18)
    at Module._extensions..js (internal/modules/cjs/loader.js:962:10)
    at Object.require.extensions..js (D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\node_modules\sapper\dist\core.js:884:5)
    at Module.load (internal/modules/cjs/loader.js:798:32)
    at Function.Module._load (internal/modules/cjs/loader.js:711:12)
    at Module.require (internal/modules/cjs/loader.js:838:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Function.load_config (D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\node_modules\sapper\dist\core.js:888:18)
    at async Object.create_compilers (D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\node_modules\sapper\dist\core.js:1119:18)
    at async Watcher.init (D:\Users\mrbub\OneDrive\dev\Educational Projects\SvelteJS - Udemy\sapper_working_dir\node_modules\sapper\dist\dev.js:215:21)
(node:19296) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:19296) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

### tl;dr the fix fixed it for me

I have encountered the same issue. Interesting is that it has worked the last time I did something on this project on 31.8. and I haven't touched it or node since then. The node version was alvays 12.8.

Anyway, I am using a JUNCTION

 Directory of C:\
    <JUNCTION>     repos [C:\Users\Qwerty\repos]

and moreover, I am running this project from git's bash via /c/repos/fotogalerie.

The console.log(filename, input); // ADD THIS LINE outputted this
C:\Users\Qwerty\repos\fotogalerie\rollup.config.js c:\repos\fotogalerie\rollup.config.js
and removal of the filename === input condition as suggested in @Conduitry's second snippet FIXED it for me. Nice catch!

It's 2020 and It's not solved yet. I have the same problem in MacOS. Any updates?

Solved this issue by replacing newest rollup.config.js from template. Seems like a backward incompatibility.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mylastore picture mylastore  路  3Comments

nikku picture nikku  路  4Comments

Rich-Harris picture Rich-Harris  路  3Comments

UnwrittenFun picture UnwrittenFun  路  4Comments

milosdjakovic picture milosdjakovic  路  3Comments