hirotaka / storybook-addon-nuxt

This add-on makes it easier to set up Storybook in your Nuxt3 project.
78 stars 16 forks source link

add "type": "module", #24

Open g1ronn1mo opened 11 months ago

g1ronn1mo commented 11 months ago

I got the Error:

import { fileURLToPath } from 'node:url';
ERR! ^^^^^^
ERR!
ERR! SyntaxError: Cannot use import statement outside a module
ERR!     at internalCompileFunction (node:internal/vm:73:18) 

Solution:

add "type": "module", to the package.json file inside the storybook-addon-nuxt folder.

DenFin commented 11 months ago

had the same issue, adding this to the package.json fixed it for me

p4trykJ commented 10 months ago

@hirotaka any chance to merge this one?

Blaquewithaq commented 10 months ago

Here's a script until fix has been merged:

/* eslint-disable no-console */
import { promises as fsPromises } from "fs";
import path from "path";

const packageJsonPath = path.join(
  "node_modules",
  "storybook-addon-nuxt",
  "package.json",
);

async function fixPackageJson() {
  try {
    const packageJsonContent = await fsPromises.readFile(
      packageJsonPath,
      "utf-8",
    );
    const packageJson = JSON.parse(packageJsonContent);

    if (!packageJson.type) {
      packageJson.type = "module";
      await fsPromises.writeFile(
        packageJsonPath,
        JSON.stringify(packageJson, null, 2),
      );
      console.log("Fixed package.json for storybook-addon-nuxt");
    } else {
      console.log("package.json already contains the 'type' property.");
    }

    // eslint-disable-next-line @typescript-eslint/no-explicit-any
  } catch (error: any) {
    console.error("Error fixing package.json:", error.message);
  }
}

fixPackageJson();