升级到 Snowpack 3 后找不到文件

问题描述

我正在使用 Snowpack + Svelte。升级到 Snowpack 3 后不再工作,我无法在 mount 中正确配置 snowpack.config.js

不明白为什么它找不到 App.js 并且它试图找到 .jsx.ts...

[404] /_dist_/screens/App.js

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="stylesheet" href="global.css">
    <script type="module" defer src="_dist_/main.js"></script>
</head>

<body>
</body>
</html>

然后在我的snowpack.config.js

/** @type {import("snowpack").SnowpackUserConfig } */
module.exports = {
  mount: {
    public: '/',src: '/_dist_',},plugins: [
    '@snowpack/plugin-svelte','@snowpack/plugin-dotenv',],routes: [
    /* Enable an SPA Fallback in development: */
    // {"match": "routes","src": ".*","dest": "/index.html"},optimize: {
    /* Example: Bundle your final build: */
    // "bundle": true,packageOptions: {
    /* ... */
  },devOptions: {
    /* ... */
  },buildOptions: {
    /* ... */
  },alias: {
    components: './src/components',screens: './src/screens',lib: './src/lib'
  },};

我也试过:

  mount: {
    // Same behavior as the "src" example above:
    "src": {url: "/dist"},// Mount "public" to the root URL path ("/*") and serve files with zero transformations:
    "public": {url: "/",static: true,resolve: false}
  },

所以现在抱怨减少了,但仍然不起作用

[snowpack] [404] /_dist_/main.js

文件结构

root
--node-modules
--public
----global.css
----index.html
--src
----components
----lib
----screens
----main.js
--snowpack.config.js
...

package.json

  "devDependencies": {
    "@snowpack/plugin-dotenv": "^2.0.5","@snowpack/plugin-svelte": "^3.5.0","@snowpack/web-test-runner-plugin": "^0.2.1","@testing-library/svelte": "^3.0.3","@web/test-runner": "^0.12.2","chai": "^4.2.0","smart-webcomponents": "^9.0.0","snowpack": "^3.0.10","svelte": "^3.31.2","svelte-i18n": "^3.3.0"
  }

任何帮助或想法将不胜感激。

解决方法

只需在导入组件时添加 .svelte

import App from 'screens/App.svelte'

如果您想深入了解,请查看此 https://github.com/snowpackjs/snowpack/pull/2014#issuecomment-756624333

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...