mjeanroy / rollup-plugin-license

Rollup plugin to add license banner to the final bundle and output third party licenses
MIT License
114 stars 21 forks source link

Error while trying to use with astro #1201

Closed oliwierzgorniak closed 2 years ago

oliwierzgorniak commented 2 years ago

Hi, i get an error while trying to build my astro project with the plugin. Does anyone have any idea what to do?

Error:

node:internal/modules/cjs/loader:933
const err = new Error(message);
              ^

Error: Cannot find module 'package.json'
Require stack:
- /home/oliwier/work/portfolio/webiste/node_modules/rollup-plugin-license/dist/index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at new LicensePlugin (/home/oliwier/work/portfolio/webiste/node_modules/rollup-plugin-license/dist/index.js:820:17)
    at licensePlugin (/home/oliwier/work/portfolio/webiste/node_modules/rollup-plugin-license/dist/index.js:1340:10)
    at rollupPluginLicense (/home/oliwier/work/portfolio/webiste/node_modules/rollup-plugin-license/dist/index.js:1351:18)
    at file:///home/oliwier/work/portfolio/webiste/astro.config.mjs:12:7
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/oliwier/work/portfolio/webiste/node_modules/rollup-plugin-license/dist/index.js'
  ]
}

My astro config file:

import { defineConfig } from "astro/config";
import react from "@astrojs/react";
import tailwind from "@astrojs/tailwind";
import license from "rollup-plugin-license";
import path from "path";

// https://astro.build/config
export default defineConfig({
  integrations: [react(), tailwind()],
  vite: {
    plugins: [
      license({
        sourcemap: true,
        cwd: ".", // Default is process.cwd()
        // banner: {
        //   commentStyle: "ignored", // The default
        //   content: {
        //     file: path.join(__dirname, "LICENSE"),
        //     encoding: "utf-8", // Default is utf-8
        //   },
        // },
        thirdParty: {
          includePrivate: true, // Default is false.
          output: {
            file: path.join("dist", "dependencies.txt"),
          },
        },
      }),
    ],
  },
});

My package.json file:

{
  "name": "@example/minimal",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "dev": "astro dev --host",
    "start": "astro dev",
    "build": "astro build",
    "preview": "astro preview"
  },
  "devDependencies": {
    "@astrojs/react": "^0.4.2",
    "@astrojs/tailwind": "^0.2.5",
    "astro": "^1.0.0-rc.6",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "rollup-plugin-license": "^2.8.1",
    "sass": "^1.54.3",
    "tailwindcss": "^3.1.8"
  },
  "dependencies": {
    "framer-motion": "^7.1.2"
  }
}
mjeanroy commented 2 years ago

Hi @oliwierzgorniak , Could you share a reproducible test case (for example, I repo that I can fork)?

oliwierzgorniak commented 2 years ago

done :) https://github.com/oliwierzgorniak/astro-license-plugin-error

VincentDauliac commented 2 years ago

Same problem with a vue app bundled with vite :/

VincentDauliac commented 2 years ago

@oliwierzgorniak, here is your problem : cwd: ".", // Default is process.cwd()

You need to restore the default value : process.cwd() instead of "."

oliwierzgorniak commented 2 years ago

@VincentDauliac thank you for your help. It worked 🥳

mjeanroy commented 2 years ago

Thanks @VincentDauliac! I need to update the readme, the default is perfectly fine for most use cases, and this line is misleading :)