i have a package which uses ES modules, with "type": "module", in my package.json. if i remove that line, the build process completes successfully¹. however, if i keep it, it seems like the es module is not recognised because i get this error:
failed to load config from /foo/vite.config.js
error during build:
/foo/node_modules/vite-dts/dist/esm/plugin.js:1
import loadJSON from 'load-json-file';
^^^^^^
SyntaxError: Cannot use import statement outside a module
not sure if this is an issue with the plugin, or something wrong with my setup. here's my vite.config.js:
// @ts-check
import { defineConfig } from "vite";
import dts from "vite-dts";
import react from "@vitejs/plugin-react";
export default defineConfig({
build: {
lib: {
entry: "src/index.ts",
// fileName: (format) => `index.${format}.js`,
formats: ["es", "cjs"],
// name: "index.js",
},
rollupOptions: {
// externalize deps that shouldn't be bundled
// into your library
external: ["react", "react-dom"],
output: {
// Provide global variables to use in the UMD build
// for externalized deps
globals: {
react: "React",
},
// Since we publish our ./src folder, there's no point
// in bloating sourcemaps with another copy of it.
sourcemapExcludeSources: true,
},
},
sourcemap: true,
target: "esnext",
minify: false,
},
plugins: [dts(), react()],
});
¹ the process completes successfully, but the type definition files are not actually generated, i suspect it's related to #5.
i have a package which uses ES modules, with
"type": "module",
in mypackage.json
. if i remove that line, the build process completes successfully¹. however, if i keep it, it seems like the es module is not recognised because i get this error:not sure if this is an issue with the plugin, or something wrong with my setup. here's my
vite.config.js
:¹ the process completes successfully, but the type definition files are not actually generated, i suspect it's related to #5.