【问题标题】:SvelteKit dev server doesn't startSvelteKit 开发服务器无法启动
【发布时间】:2020-12-13 15:15:14
【问题描述】:

我想试用 Sapper 的新 SvelteKit 替代品,但我无法启动开发服务器。

我跑了:

npm init svelte@next
npm install
npm run dev -- --open

错误:

(node:16570) UnhandledPromiseRejectionWarning: .../Desktop/Programming/Web Development/Svelte/Demo-app/node_modules/@sveltejs/kit/dist/index4.js:262
        #map;
        ^

SyntaxError: Invalid or unexpected token
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    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:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (../Desktop/Programming/Web Development/Svelte/Demo-app/node_modules/@sveltejs/kit/dist/index.js:13:13)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
(node:16570) 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: 2)
(node:16570) [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.

我没有碰过生成的代码。

我知道当服务器启动时无法打开新的浏览器选项卡时会弹出这类错误,但我不知道如何在此处修复。

  • 节点版本:v10.19.0
  • 操作系统:Ubuntu 20.04.1 LTS,64 位
  • 浏览器:Firefox 83.0(64 位)
  • 代理:Burp Suite

【问题讨论】:

    标签: javascript node.js svelte


    【解决方案1】:

    我猜#map 是一些private class field,从节点 12 开始支持。

    您可以尝试使用 node 12 或更新的版本。

    【讨论】:

    • 你说的是真的。作为旁注,我们可以查看package.json 来查看"engines": {"node": "&gt;= xxx"} 之类的内容。在我的情况下,xxx 是12.17.0
    【解决方案2】:

    我猜你正在尝试制作模板并使用模板语法

    {#map bla bla}
    

    那么错误可能只是不支持map,您可能必须切换到#each

    {#each expression as name}...{/each}
    

    【讨论】:

    • 错误指向node_modules,我还没有开始编码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-21
    • 2016-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-06
    相关资源
    最近更新 更多