Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rollup version is too old #76

Open
huhuang03 opened this issue Feb 20, 2023 · 3 comments
Open

rollup version is too old #76

huhuang03 opened this issue Feb 20, 2023 · 3 comments

Comments

@huhuang03
Copy link

huhuang03 commented Feb 20, 2023

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:

rollup/rollup#4446 (comment)

rollup/rollup#3481 (comment)

@mrwilbroad
Copy link

The same error come to my code :

[email protected] 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
Copy link

The same error come to my code :

[email protected] 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
Copy link

This git repo needs to be updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants