i have to create a module to use on my application, but when I import that in my major project i have this error
JavaScript
x
2
1
Error: Cannot find module '.../node_modules/Table/dist/index.js'. Please verify that the package.json has a valid "main" entry
2
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. My version of node is v12.16.2
I update my rollup to build with npm run dev
Here there is my new rollup
JavaScript
1
18
18
1
import svelte from 'rollup-plugin-svelte';
2
import resolve from 'rollup-plugin-node-resolve';
3
4
const pkg = require('./package.json');
5
6
export default {
7
input: 'src/Table.svelte',
8
output: {
9
file: `dist/bundle.js`,
10
format: "iife"
11
},
12
plugins: [
13
svelte(),
14
resolve({ preferBuiltins: true, mainFields: ['browser'] })
15
],
16
external: ['uuid', 'object-exporter']
17
};
18
But i have again this error
JavaScript
1
6
1
internal/modules/cjs/loader.js:327
2
throw err;
3
^
4
5
Error: Cannot find module '/../../node_modules/Table/dist/index.js'. Please verify that the package.json has a valid "main" entry
6
Advertisement
Answer
Your rollup config build your package in dist/bundle.js
:
JavaScript
1
5
1
output: {
2
file: `dist/bundle.js`,
3
format: "iife"
4
},
5
But you probably defined in your package.json
:
JavaScript
1
2
1
"main": "dist/index.js",
2
But dist/index.js
doesn’t exits. Just replace it with "main": "dist/bundle.js"
.