Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Rest route index page crash on compile #709

Closed
IlyaSemenov opened this issue May 22, 2019 · 2 comments
Closed

Rest route index page crash on compile #709

IlyaSemenov opened this issue May 22, 2019 · 2 comments

Comments

@IlyaSemenov
Copy link

IlyaSemenov commented May 22, 2019

Extracted from #706 as it's an unrelated issue.

  • /routes/[...categories]/[item].html.svelte - this one works
  • neither /routes/[...categories].svelte or /routes/[...categories]/index.svelte works:
❯ yarn dev
yarn run v1.16.0
warning package.json: No license field
$ sapper dev
✗ client
src/routes/[...categories]/index.svelte
Module build failed (from ./node_modules/svelte-loader/index.js):
Error: TypeError: TypeError: Cannot read property 'toUpperCase' of undefined
✗ server
src/routes/[...categories]/index.svelte
Module build failed (from ./node_modules/svelte-loader/index.js):
Error: TypeError: TypeError: Cannot read property 'toUpperCase' of undefined
✔ service worker (168ms)
webpack:///./src/routes/%5B...categories%5D/index.svelte?:1
throw new Error("Module build failed (from ./node_modules/svelte-loader/index.js):\nError: TypeError: TypeError: Cannot read property 'toUpperCase' of undefined\n    at preprocess.then.catch.err (/Users/semenov/tmp/my-app/node_modules/svelte-loader/index.js:180:12)");
^

Error: Module build failed (from ./node_modules/svelte-loader/index.js):
Error: TypeError: TypeError: Cannot read property 'toUpperCase' of undefined
    at preprocess.then.catch.err (/Users/semenov/tmp/my-app/node_modules/svelte-loader/index.js:180:12)
    at eval (webpack:///./src/routes/%5B...categories%5D/index.svelte?:1:7)
    at Object../src/routes/[...categories]/index.svelte (/Users/semenov/tmp/my-app/__sapper__/dev/server/server.js:193:1)
    at __webpack_require__ (/Users/semenov/tmp/my-app/__sapper__/dev/server/server.js:21:30)
    at eval (webpack:///./src/node_modules/@sapper/internal/manifest-server.mjs?:12:89)
    at Module../src/node_modules/@sapper/internal/manifest-server.mjs (/Users/semenov/tmp/my-app/__sapper__/dev/server/server.js:158:1)
    at __webpack_require__ (/Users/semenov/tmp/my-app/__sapper__/dev/server/server.js:21:30)
    at eval (webpack:///./src/node_modules/@sapper/server.mjs?:5:83)
    at Module../src/node_modules/@sapper/server.mjs (/Users/semenov/tmp/my-app/__sapper__/dev/server/server.js:182:1)
    at __webpack_require__ (/Users/semenov/tmp/my-app/__sapper__/dev/server/server.js:21:30)
    at eval (webpack:///./src/server.js?:8:72)
> Server crashed

Tested on a brand new install of npx degit sveltejs/sapper-template#webpack my-app with only one file added at src/routes/[...categories]/index.svelte:

<h1>cat index</h1>

I traced this to be caused by Svelte's code:

    function get_name(filename) {
        if (!filename)
            return null;
        const parts = filename.split(/[\/\\]/);
        if (parts.length > 1 && /^index\.\w+/.test(parts[parts.length - 1])) {
            parts.pop();
        }
        const base = parts.pop()
            .replace(/\..+/, "") // <------ here [...categories] becomes [
            .replace(/[^a-zA-Z_$0-9]+/g, '_') // <------ here it becomes _
            .replace(/^_/, '') // <------ here it becomes empty
            .replace(/_$/, '')
            .replace(/^(\d)/, '_$1');
        return base[0].toUpperCase() + base.slice(1); // here it crashes
    }
@jumpinggoofballs
Copy link

I get the same thing on the rollup template.

@Conduitry
Copy link
Member

As noted in the linked issue, this is a Svelte bug. Closing this one.

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

No branches or pull requests

3 participants