Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获类型错误:svmd_es.Button不是在svelte中实现UI工具包的构造函数_Javascript_Svelte_Rollupjs_Svelte 3_Svelte Component - Fatal编程技术网

Javascript 未捕获类型错误:svmd_es.Button不是在svelte中实现UI工具包的构造函数

Javascript 未捕获类型错误:svmd_es.Button不是在svelte中实现UI工具包的构造函数,javascript,svelte,rollupjs,svelte-3,svelte-component,Javascript,Svelte,Rollupjs,Svelte 3,Svelte Component,我是新来的苗条和尝试材料设计工具包为我的第一次实验。我发现,这看起来不错,我把它添加到我的苗条项目中 根据文档,除了导入组件并使用它们之外,没有其他事情了。但是,这在浏览器中给了我以下错误: Uncaught TypeError: svmd_es.Button is not a constructor create_fragment bundle.js:798 init index.mjs:1451 App bundle.js:873 app main.js:4

我是新来的苗条和尝试材料设计工具包为我的第一次实验。我发现,这看起来不错,我把它添加到我的苗条项目中

根据文档,除了导入组件并使用它们之外,没有其他事情了。但是,这在浏览器中给了我以下错误:

Uncaught TypeError: svmd_es.Button is not a constructor
    create_fragment bundle.js:798
    init index.mjs:1451
    App bundle.js:873
    app main.js:4
    <anonymous> bundle.js:890
App.svelte

import App from './App.svelte';

const app = new App({
    target: document.body
});

export default app;
<script>
    import { Button, Slider, Fab } from 'svmd';
    import 'svmd/dist/svmd.css';
</script>

<main>
    <Button>flat button</Button>
    Lets see a button.
</main>

<style>
</style>
import svelte from 'rollup-plugin-svelte';
import scss from 'rollup-plugin-scss';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';

const production = !process.env.ROLLUP_WATCH;

function serve() {
    let server;
    
    function toExit() {
        if (server) server.kill(0);
    }

    return {
        writeBundle() {
            if (server) return;
            server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
                stdio: ['ignore', 'inherit', 'inherit'],
                shell: true
            });

            process.on('SIGTERM', toExit);
            process.on('exit', toExit);
        }
    };
}

export default {
    input: 'src/main.js',
    output: {
        sourcemap: true,
        format: 'iife',
        name: 'app',
        file: 'public/build/bundle.js'
    },
    plugins: [
        svelte({
            // enable run-time checks when not in production
            dev: !production,
            // we'll extract any component CSS out into
            // a separate file - better for performance
            css: css => {
                css.write('public/build/bundle.css');
            }
        }),

        // If you have external dependencies installed from
        // npm, you'll most likely need these plugins. In
        // some cases you'll need additional configuration -
        // consult the documentation for details:
        // https://github.com/rollup/plugins/tree/master/packages/commonjs
        scss(),
        resolve({
            browser: true,
            dedupe: ['svelte']
        }),
        commonjs(),

        // In dev mode, call `npm run start` once
        // the bundle has been generated
        !production && serve(),

        // Watch the `public` directory and refresh the
        // browser on changes when not in production
        !production && livereload('public'),

        // If we're building for production (npm run build
        // instead of npm run dev), minify
        production && terser()
    ],
    watch: {
        clearScreen: false
    }
};
{
  "name": "svelteapp",
  "version": "1.0.0",
  "scripts": {
    "build": "rollup -c",
    "dev": "rollup -c -w",
    "start": "sirv public"
  },
  "devDependencies": {
    "@rollup/plugin-commonjs": "^14.0.0",
    "@rollup/plugin-node-resolve": "^8.4.0",
    "rollup": "^2.3.4",
    "rollup-plugin-livereload": "^1.0.0",
    "rollup-plugin-scss": "^2.6.0",
    "rollup-plugin-svelte": "^5.0.3",
    "rollup-plugin-terser": "^7.0.0",
    "svelte": "^3.0.0",
    "svmd": "^0.3.1"
  },
  "dependencies": {
    "sirv-cli": "^1.0.0"
  }
}
package.json

import App from './App.svelte';

const app = new App({
    target: document.body
});

export default app;
<script>
    import { Button, Slider, Fab } from 'svmd';
    import 'svmd/dist/svmd.css';
</script>

<main>
    <Button>flat button</Button>
    Lets see a button.
</main>

<style>
</style>
import svelte from 'rollup-plugin-svelte';
import scss from 'rollup-plugin-scss';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';

const production = !process.env.ROLLUP_WATCH;

function serve() {
    let server;
    
    function toExit() {
        if (server) server.kill(0);
    }

    return {
        writeBundle() {
            if (server) return;
            server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
                stdio: ['ignore', 'inherit', 'inherit'],
                shell: true
            });

            process.on('SIGTERM', toExit);
            process.on('exit', toExit);
        }
    };
}

export default {
    input: 'src/main.js',
    output: {
        sourcemap: true,
        format: 'iife',
        name: 'app',
        file: 'public/build/bundle.js'
    },
    plugins: [
        svelte({
            // enable run-time checks when not in production
            dev: !production,
            // we'll extract any component CSS out into
            // a separate file - better for performance
            css: css => {
                css.write('public/build/bundle.css');
            }
        }),

        // If you have external dependencies installed from
        // npm, you'll most likely need these plugins. In
        // some cases you'll need additional configuration -
        // consult the documentation for details:
        // https://github.com/rollup/plugins/tree/master/packages/commonjs
        scss(),
        resolve({
            browser: true,
            dedupe: ['svelte']
        }),
        commonjs(),

        // In dev mode, call `npm run start` once
        // the bundle has been generated
        !production && serve(),

        // Watch the `public` directory and refresh the
        // browser on changes when not in production
        !production && livereload('public'),

        // If we're building for production (npm run build
        // instead of npm run dev), minify
        production && terser()
    ],
    watch: {
        clearScreen: false
    }
};
{
  "name": "svelteapp",
  "version": "1.0.0",
  "scripts": {
    "build": "rollup -c",
    "dev": "rollup -c -w",
    "start": "sirv public"
  },
  "devDependencies": {
    "@rollup/plugin-commonjs": "^14.0.0",
    "@rollup/plugin-node-resolve": "^8.4.0",
    "rollup": "^2.3.4",
    "rollup-plugin-livereload": "^1.0.0",
    "rollup-plugin-scss": "^2.6.0",
    "rollup-plugin-svelte": "^5.0.3",
    "rollup-plugin-terser": "^7.0.0",
    "svelte": "^3.0.0",
    "svmd": "^0.3.1"
  },
  "dependencies": {
    "sirv-cli": "^1.0.0"
  }
}

希望有人能帮助我。

您提到的库在捆绑发布时似乎有一些错误。如果您直接引用源组件本身,您的运气会更好

import { Button, Slider, Fab } from 'svmd/src';
也就是说,它似乎不再积极发展


如果你想要材料设计,你可能想看看

我想你需要使用插件从
node\u模块编译包
是的,你可以看到我已经尝试过了。我已经在resolve\include配置中添加了
node\u modules/svmd/***
,但是它不再编译了。如果你知道启用它的正确方法,请告诉我。你必须使用插件解决它。你能试试这个配置吗:
插件:[nodeResolve({resolveOnly:['svmd']})]
这确实给了我一个不同的错误。编译工作,浏览器现在显示
未捕获引用错误:未定义内部
包中的某个地方…似乎是另一个问题,请提供包。json,这样我就可以在本地测试它了