简体   繁体   English

在 svelte 上导入 node_module 时出错

[英]Error when import a node_module on svelte

i have to create a module to use on my application, but when I import that in my major project i have this error我必须创建一个模块以在我的应用程序上使用,但是当我在我的主要项目中导入它时出现此错误

Error: Cannot find module '.../node_modules/Table/dist/index.js'. Please verify that the package.json has a valid "main" entry

I have not the folder dist/index.js, in the guide I followed I did not see that it was necessary to make the package, also in another project i did not have these problems.我没有文件夹 dist/index.js,在我遵循的指南中我没有看到有必要制作包,也在另一个项目中我没有这些问题。 My version of node is v12.16.2我的节点版本是 v12.16.2


I update my rollup to build with npm run dev我更新我的汇总以使用npm run dev构建

Here there is my new rollup这是我的新汇总

import svelte from 'rollup-plugin-svelte';
import resolve from 'rollup-plugin-node-resolve';
    
const pkg = require('./package.json');
    
export default {
        input: 'src/Table.svelte',
        output: {
            file: `dist/bundle.js`,
            format: "iife"
        },
        plugins: [
            svelte(),
            resolve({ preferBuiltins: true, mainFields: ['browser'] })
        ],
        external: ['uuid', 'object-exporter']
};

But i have again this error但我又犯了这个错误

internal/modules/cjs/loader.js:327
      throw err;
      ^

Error: Cannot find module '/../../node_modules/Table/dist/index.js'. Please verify that the package.json has a valid "main" entry

Your rollup config build your package in dist/bundle.js :你的汇总配置在dist/bundle.js构建你的包:

output: {
    file: `dist/bundle.js`,
    format: "iife"
},

But you probably defined in your package.json :但您可能在package.json定义:

  "main": "dist/index.js",

But dist/index.js doesn't exits.但是dist/index.js没有退出。 Just replace it with "main": "dist/bundle.js" .只需将其替换为"main": "dist/bundle.js"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM