rollup / rollup-starter-lib

Bare-bones example of how to create a library using Rollup
MIT License
961 stars 230 forks source link

rollup version is too old #76

Open huhuang03 opened 1 year ago

huhuang03 commented 1 year ago

If I use lates rollup 3.17.2 (now is 1.29.0), then I run yarn run dev, the error throws:

rollup-starter-lib [master] % yarn run build
yarn run v1.22.19
$ rollup -c
(node:70006) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
[!] RollupError: Node tried to load your configuration file as CommonJS even though it is likely an ES module. To resolve this, change the extension of your configuration to ".mjs", set "type": "module" in your package.json file or pass the "--bundleConfigAsCjs" flag.

Original error: Cannot use import statement outside a module
https://rollupjs.org/command-line-interface/#bundleconfigascjs
/Users/hwf/source/rollup-starter-lib/rollup.config.js:3
import pkg from './package.json';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1001:16)
    at Module._compile (internal/modules/cjs/loader.js:1049:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:203:29)
    at ModuleJob.run (internal/modules/esm/module_job.js:183:25)
    at async Loader.import (internal/modules/esm/loader.js:178:24)
    at async getConfigFileExport (/Users/hwf/source/rollup-starter-lib/node_modules/rollup/dist/shared/loadConfigFile.js:432:17)
    at async Object.loadConfigFile (/Users/hwf/source/rollup-starter-lib/node_modules/rollup/dist/shared/loadConfigFile.js:391:59)

Seems like need do this if want use rollup3.x:

https://github.com/rollup/rollup/issues/4446#issuecomment-1086560014

https://github.com/rollup/rollup/issues/3481#issuecomment-1412016434

mrwilbroad commented 6 months ago

The same error come to my code :

react-calculator-v1@0.0.1 rollup
> rollup -c

(node:14918) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
[!] RollupError: Node tried to load your configuration file as CommonJS even though it is likely an ES module. To resolve this, change the extension of your configuration to ".mjs", set "type": "module" in your package.json file or pass the "--bundleConfigAsCjs" flag.

Original error: Cannot use import statement outside a module
https://rollupjs.org/command-line-interface/#bundleconfigascjs
/var/www/html/coding/Packages/react-calculator-v1/rollup.config.js:1
import resolve from "@rollup/plugin-node-resolve";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)
    at Module._compile (node:internal/modules/cjs/loader:1340:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at cjsLoader (node:internal/modules/esm/translators:345:17)

any assistance please

mrwilbroad commented 6 months ago

The same error come to my code :

react-calculator-v1@0.0.1 rollup
> rollup -c

(node:14918) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
[!] RollupError: Node tried to load your configuration file as CommonJS even though it is likely an ES module. To resolve this, change the extension of your configuration to ".mjs", set "type": "module" in your package.json file or pass the "--bundleConfigAsCjs" flag.

Original error: Cannot use import statement outside a module
https://rollupjs.org/command-line-interface/#bundleconfigascjs
/var/www/html/coding/Packages/react-calculator-v1/rollup.config.js:1
import resolve from "@rollup/plugin-node-resolve";
^^^^^^

SyntaxError: Cannot use import statement outside a module
 at internalCompileFunction (node:internal/vm:77:18)
 at wrapSafe (node:internal/modules/cjs/loader:1288:20)
 at Module._compile (node:internal/modules/cjs/loader:1340:27)
 at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
 at Module.load (node:internal/modules/cjs/loader:1207:32)
 at Module._load (node:internal/modules/cjs/loader:1023:12)
 at cjsLoader (node:internal/modules/esm/translators:345:17)

any assistance please

Solution

i config rollup.config.mjs like this though before i saved file as rollup.config.js

import resolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import commonjs from "@rollup/plugin-commonjs";
import dts from "rollup-plugin-dts";

// rollup.config.js (building more than one bundle)
export default [
  {
    input: "src/index.ts",
    output: [
      {
        file: "dist/cjs/index.js",
        format: "cjs",
        sourcemap: true,
      },
      {
        file: "dist/esm/index.js",
        format: "esm",
        sourcemap: true,
      },
    ],
    plugins: [
      resolve(),
      commonjs(),
      typescript({ tsconfig: "./tsconfig.json" }),
    ],
  },
  {
    input: "dist/esm/types/index.d.ts",
    output: [{ file: "dist/index.d.ts", format: "esm" }],
    plugins: [dts()],
  },
];
trymeouteh commented 2 months ago

This git repo needs to be updated