EC-Nordbund / rollup-plugin-leaflet

0 stars 0 forks source link

[question]: when i use "--bundleConfigAsCjs" flag for import "plugin-node-resolve", the leaflet plugin cant be resolved #6

Open AhXianGL opened 1 year ago

AhXianGL commented 1 year ago

// some blocks in my package.json "devDependencies": { "@ec-nordbund/rollup-plugin-leaflet": "^1.0.0", "@rollup/plugin-commonjs": "^25.0.2", "@rollup/plugin-node-resolve": "^15.1.0", "rollup": "^3.26.2" }, "scripts": { "build": "rollup --config --bundleConfigAsCjs", },

// rollup.config.js
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { defineConfig } from 'rollup';
import leaflet from "@ec-nordbund/rollup-plugin-leaflet";

export default defineConfig({
  input: 'src/index.js',
  output: [
  {
    format: 'esm',
    name: 'LeafletMapViewContext',
    file: 'dist/leaflet-mapview-context.mjs',
  },{
    format:'iife',
    name: 'LeafletMapViewContext',
    file:'dist/leaflet-mapview-context.js',
    globals:{
      leaflet:'leaflet',
    }
  },
],
  treeshake: 'recommended',
  plugins: [
    commonjs(),
    leaflet(),
    resolve(),
  ],
});

after npm run build , terminal show some error like this: [!] Error: Must use import to load ES Module: F:\Folder-ssx\Code\leafletmapviewcontext\node_modules\@ec-nordbund\rollup-plugin-leaflet\dist\index.js require() of ES modules is not supported. require() of F:\Folder-ssx\Code\leafletmapviewcontext\node_modules\@ec-nordbund\rollup-plugin-leaflet\dist\index.js from F:\Folder-ssx\Code\leafletmapviewcontext\rollup.config-1689657728634.cjs is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from F:\Folder-ssx\Code\leafletmapviewcontext\node_modules\@ec-nordbund\rollup-plugin-leaflet\package.json.

AhXianGL commented 1 year ago

when i remove the bundleConfigAsCjs flag, the rollup.config.js file will go wrong, SyntaxError: Cannot use import statement outside a module: import resolve from '@rollup/plugin-node-resolve';