fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.91k stars 878 forks source link

Unable to resolve some modules: "./lib-cov/fluent-ffmpeg" #573

Closed Jaetoh closed 8 years ago

Jaetoh commented 8 years ago

Hi !

I got this warning while running my Meteor app with the npm package fluent-ffmpeg. I don't really know what's wrong with this issue because my npm package worked well during more than 3 months. After I installed again all npm packages into my app, i got it.

Unable to resolve some modules:

"./lib-cov/fluent-ffmpeg" in /home/.../MyAPP/node_modules/fluent-ffmpeg/index.js (web.browser)

Unable to resolve some modules:

"./lib-cov/fluent-ffmpeg" in /home/.../MyAPP/node_modules/fluent-ffmpeg/index.js (os.linux.x86_64)

Thank you in advance for any reply

njoyard commented 8 years ago

Hey,

This is weird, items in lib-cov should only be referenced during CI. Here is the code from index.js:

module.exports = process.env.FLUENTFFMPEG_COV ? require('./lib-cov/fluent-ffmpeg') : require('./lib/fluent-ffmpeg');

Do you happen to have the environment variable FLUENTFFMPEG_COV set by any chance ? If so, then unsetting it will probably solve the issue.

Jaetoh commented 8 years ago

I exactly have the same code for index.js ! I didn’t set by myself the environment variable FLUENTFFMPEG_COV. Maybe it has been modified during a process but i don't think.

I am on Ubuntu 14.04 and i work with Meteor ! I tried to remove the npm package and reinstall it but it is same result. I also did npm rebuild

Here is the line related to lib-cov in the makefile :

test/coverage.html: lib-cov
    @FLUENTFFMPEG_COV=0 NODE_ENV=test $(MOCHA) --require should --reporter html-cov > test/coverage.html
chervox commented 8 years ago

Hi Jaetoh, I'm having the exact same problem. Are you using webpack by any chance? I think that the issue is because of trying to solve the path statically:

Here is the offending line: index.js: module.exports = process.env.FLUENTFFMPEG_COV ? require('./lib-cov/fluent-ffmpeg') : require('./lib/fluent-ffmpeg');

Jaetoh commented 8 years ago

I'm not using webpack ! Did you figure out the warning ?

njoyard commented 8 years ago

@Jaetoh this is a Meteor bug. It parses source files and tries to include everything that is in a require() call, even if it's conditional. Nothing fluent-ffmpeg can do here.

agmcleod commented 7 years ago

Given that webpack has issue resolving this, and that ES6 imports are not done conditionally, is this something you can consider fixing?

kus commented 7 years ago

I ran into this also when using Webpack as I'm building a desktop app using this library.

The work around (if you are using Webpack):

plugins: [
    new webpack.DefinePlugin({
        'process.env.FLUENTFFMPEG_COV': false
    })
]

If not using Webpack you could just put FLUENTFFMPEG_COV=0 at the start of your npm script.

crakjie commented 7 years ago

I'm running into the same problem with https://github.com/electron-userland/electron-builder

Jfeng3 commented 7 years ago

New to javascript. I am using react-scripts and running into same issue I am trying to use kus @kus 's approach inside

react-scripts/config/webpack.config.dev.js

I can find

plugins: [
  new webpack.DefinePlugin(env.stringified)
]

what should I do with it? replace with


plugins: [
    new webpack.DefinePlugin({
        'process.env.FLUENTFFMPEG_COV': false
    })
]?``` 
kus commented 7 years ago

@Jfeng3 assuming your env.stringified is an Object which it should be, you should check it by adding console.log('env', env.stringified) at the end of your WebPack script and run it to make sure it is. It should equal something like:

{
    'process.env.NODE_ENV': 'development'
}

The important thing is it being an Object. If it is; you can inject the new variable in one of the following ways:

This depends how you are running Webpack, if you get an error like SyntaxError: Unexpected token ... use the next one after.

plugins: [
    new webpack.DefinePlugin({
        ...env.stringified,
        'process.env.FLUENTFFMPEG_COV': false
    })
]
plugins: [
    new webpack.DefinePlugin(Object.assign({}, env.stringified, {'process.env.FLUENTFFMPEG_COV': false}))
]
michaelmaitland commented 4 years ago

this is still an issue for me

when i do yarn add fluent-ffmpeg:

WARNING in ./node_modules/electron-debug/index.js 96:45-58
Critical dependency: the request of a dependency is an expression
 @ dll renderer

WARNING in ./node_modules/electron-debug/index.js 97:61-74
Critical dependency: the request of a dependency is an expression
 @ dll renderer

WARNING in ./node_modules/fluent-ffmpeg/lib/options/misc.js 27:21-40
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/fluent-ffmpeg/lib/fluent-ffmpeg.js
 @ ./node_modules/fluent-ffmpeg/index.js
 @ dll renderer

ERROR in ./node_modules/fluent-ffmpeg/index.js
Module not found: Error: Can't resolve './lib-cov/fluent-ffmpeg' in '/Users/yasgur99/Documents/desktopapp/node_modules/fluent-ffmpeg'
 @ ./node_modules/fluent-ffmpeg/index.js 1:48-82
 @ dll renderer
tiberiumboy commented 3 years ago

Hello all, Using fluent-ffmpeg, I'm puzzle as to why it would even bother loading lib-cov if it's not included in the npm package anyway. I am actively looking for alternative solution to get around this, rather than directly modifying your index.js file to get this plugin to work. Using Angular/Electron build.

muzammal-murtaza commented 3 years ago

I ran into this also when using Webpack as I'm building a desktop app using this library.

The work around (if you are using Webpack):

plugins: [
    new webpack.DefinePlugin({
        'process.env.FLUENTFFMPEG_COV': false
    })
]

If not using Webpack you could just put FLUENTFFMPEG_COV=0 at the start of your npm script.

I am getting same issue in my Vue app, any idea how to solve this.

dancixx commented 3 years ago

Does somebody have experience what should to do in a react-app? I tried all offers but nothing works.

sharunspi commented 3 years ago

Does somebody have experience what should to do in a react-app? I tried all offers but nothing works.

If you are using webpack in react then add this configuration to your plugins object in webpack configuration


    plugins: [
      new webpack.DefinePlugin({
        'process.env.FLUENTFFMPEG_COV': false
      })
    ]
max-programming commented 3 years ago

I ran into this also when using Webpack as I'm building a desktop app using this library.

The work around (if you are using Webpack):

plugins: [
    new webpack.DefinePlugin({
        'process.env.FLUENTFFMPEG_COV': false
    })
]

If not using Webpack you could just put FLUENTFFMPEG_COV=0 at the start of your npm script.

I think this works for many people but I am using Rollup and it's not working for me. I used the Rollup approach to set the environment variable.

I ran this command but I get the same error: rollup -c --environment FLUENTFFMPEG_COV:false and also this rollup -c --environment FLUENTFFMPEG_COV:0

@kus do you have any idea why is this not working 😢

Losses commented 3 years ago

I'm running into the same problem with https://github.com/electron-userland/electron-builder

open .erb/configs/webpack.config.base.js,

replace the last section with:

  plugins: [
    new webpack.EnvironmentPlugin({
      NODE_ENV: 'production',
      FLUENTFFMPEG_COV: '',
    }),
  ],
vishal-c-addweb commented 2 years ago

i am using esbuild for bundle and running into same problem. adding 'process.env.FLUENTFFMPEG_COV' = '0' solve my problem. ----> custom: { esbuild: { define: { 'process.env.FLUENTFFMPEG_COV': '0' }, }, }
while using serverless.

PAXANDDOS commented 2 years ago

I am facing the same issue now. Working on the Electron application and I really need to use FFmpeg features. Have a custom script to serve my application, so the package.json is:

"scripts": {
    "dev": "node scripts/watch.mjs"

And right at the beginning of which I have put:

process.env.FLUENTFFMPEG_COV = false
process.env.NODE_ENV = 'development'
. . .

Also tried with an empty string and a zero, but the issue still exists... Using Vite ^2.7.13 and Node.js v17.4.0

Any idea, please?

UPD: Just checked PR #945 and edited the package directly in my node_modules and it worked! Even if this package hadn't received updates since 2017, I hope it gets bumped soon 👀

lanly-dev commented 2 years ago

This worked for me:

new EnvironmentPlugin({
  FLUENTFFMPEG_COV: '',
})
serg06 commented 2 years ago

@max-programming @PAXANDDOS I was able to fix this in Vite/Rollup by adding the following line to my Vite config:

export default defineConfig(() => ({
  resolve: {
    alias: {
      './lib-cov/fluent-ffmpeg': './lib/fluent-ffmpeg'  // This line
    },
  },
}));
asquithea commented 2 years ago

If anyone is struggling with this issue in esbuild, I got it working by writing this small plugin:

const path = require("path");

let resolveFfmpegPlugin = {
  name: "resolveFfmpeg",
  setup(build) {
    build.onResolve({ filter: /lib-cov\/fluent-ffmpeg/ }, (args) => {
      // fix https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/issues/573
      const actualPath = path.join(args.resolveDir, "lib", "fluent-ffmpeg.js");
      return { path: actualPath };
    });
  },
};
Tikam02 commented 2 years ago

plugins: [ new webpack.DefinePlugin({ 'process.env.FLUENTFFMPEG_COV': false }) ]

where to add this in React project?

vikash265 commented 2 years ago

plugins: [ new webpack.DefinePlugin({ 'process.env.FLUENTFFMPEG_COV': false }) ]

where to add this in React project?

vikash265 commented 2 years ago

plugins: [ new webpack.DefinePlugin({ 'process.env.FLUENTFFMPEG_COV': false }) ]

where to add this in React project?

oakgary commented 2 years ago

My solution when using serverless-bundle, which is a framework on top of Webpack, was to exclude fluent-ffmpeg from being built with Webpack and adding it to the node_modules/ directory instead by using

custom:
  bundle:
    externals:
      - knex
      - sharp
      - fluent-ffmpeg

Might take up a bit more space but is completely fine for my specific use case.

https://www.npmjs.com/package/serverless-bundle#externals

leumasme commented 2 years ago

In rollup, this can be solved with the plugin @rollup/plugin-alias

rollup.config.js

import alias from "@rollup/plugin-alias";
export default {
  plugins: [
    alias({
      entries: [
        { find: "./lib-cov/fluent-ffmpeg", replacement: "./lib/fluent-ffmpeg" },
      ]
    })
  ]
}
gersongams commented 1 year ago

while using serverless.

this worked for me!! thanks!

mcorrigan commented 1 year ago

I ran into this also when using Webpack as I'm building a desktop app using this library.

The work around (if you are using Webpack):

plugins: [
    new webpack.DefinePlugin({
        'process.env.FLUENTFFMPEG_COV': false
    })
]

If not using Webpack you could just put FLUENTFFMPEG_COV=0 at the start of your npm script.

This worked for me, just make sure to const webpack = require('webpack') as the top

subvertallchris commented 1 year ago

If you're using a .env file, be aware that FLUENTFFMPEG_COV=false will not treat false as a boolean. It will be read as a string. So the evaluation in code:

module.exports = process.env.FLUENTFFMPEG_COV ? require('./lib-cov/fluent-ffmpeg') : require('./lib/fluent-ffmpeg');

...will be evaluated to the true condition because 'false' is a truthy value. You can do this:

FLUENTFFMPEG_COV=''

The empty string is falsy.

PDKSophia commented 1 year ago

I also have the same problem. According to everyone's solutions, I have not solved it.

I use React+Vite+Electron. I will share some of my knowledge

when i downloaded fluent-ffmpeg,i want to import it,but i got error

then i went to the node_modules/fluent-ffmpeg folder to see its source code,the process.env.FLUENTFFMPEG_COV may be an error value.

module.exports = process.env.FLUENTFFMPEG_COV ? require('./lib-cov/fluent-ffmpeg') : require('./lib/fluent-ffmpeg');

in vite docs , we can be configured through the define attribute, so i go to configure value

// vite.config.js
export default defineConfig({
  // ...
  define: {
    'process.env.FLUENTFFMPEG_COV': false,
  },
}

And added two lines of code to the source code, print process.env.FLUENTFFMPEG_COV value

// node_modules/fluent-ffmpeg
console.log('[fluent-ffmpeg]', process.env.FLUENTFFMPEG_COV);
console.log('[fluent-ffmpeg]', typeof process.env.FLUENTFFMPEG_COV);

module.exports = process.env.FLUENTFFMPEG_COV ? require('./lib-cov/fluent-ffmpeg') : require('./lib/fluent-ffmpeg');

we expect it to be a boolean, but it's actually a string !!!

try again, this time we change it to undefined, same result !


No matter what value is configured, it is of string type and will meet the condition of true, so i try to configure as an empty string

Error , I don't know why, so hard !

The solution is to copy the fluent-ffmpeg folder, change the source code, but this is not what I expected !

when i'm depressed, i was surprised to find that the vite startup electron plugin I wrote can inject environment variables, below is my code:

import { Plugin } from 'vite';
import { buildMain, mainOutPath } from '../scripts/build.main';

export const devMainPlugin = (): Plugin => {
  return {
    name: 'vite-plugin-dev-main',
    configureServer(server) {
      buildMain();
      server.httpServer?.once('listening', () => {
        const { spawn } = require('child_process');
        const electronProcess = spawn(require('electron').toString(), [mainOutPath, '--inspect=9229', '--remote-debugging-port=9222', '--env=dev'], {
          cwd: process.cwd(),
          stdio: 'inherit',
          env: {
            FLUENTFFMPEG_COV: '',
          },
        });
        electronProcess.on('close', () => {
          server.close();
          process.exit();
        });
        server.httpServer?.once('close', () => {
          electronProcess.close();
          process.exit();
        });
      });
    },
  };
};

this way solved my problem !

Geo25rey commented 1 year ago

For those using vite-plugin-electron in their vite.config.ts

Note: I assume that you aren't using ffmpeg in your preload script. If you do, just copy over the vite property from the main entrypoint section.

import { defineConfig } from 'vite';
import electron from 'vite-plugin-electron';

export default defineConfig({
  plugins: [
    electron([
      {
        entry: "src/electron/node/main.ts", // wherever your main entrypoint 
        vite: {
          build: {
            rollupOptions: {
              plugins: [
                alias({
                  entries: [
                    {
                      find: "./lib-cov/fluent-ffmpeg",
                      replacement: "./lib/fluent-ffmpeg",
                    },
                  ],
                }),
              ],
            },
          },
        },
      },
      {
        entry: "src/electron/node/preload.ts", // wherever your preload entrypoint 
        onstart(options) {
          // Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
          // instead of restarting the entire Electron App.
          options.reload();
        },
      },
    ]),
  ]
});
Isaccseven commented 1 year ago

Is there someone, who solved this issue with next js ?

pblvrt commented 1 year ago

Is there someone, who solved this issue with next js ?

this config works

/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
    config.plugins.push(
      new webpack.DefinePlugin({
        'process.env.FLUENTFFMPEG_COV': false
    })
    )

    return config
  },
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: '*',
        port: '',
        pathname: '/**',
      },
    ],
  },
}

module.exports = nextConfig
TharukaDananjaya commented 1 year ago

Is there someone, who solved this issue with laravel mix ?

McKean commented 1 year ago

For people stumbling over this, this has been addressed but the changes have not been published since: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/68d5c948b689b3058e52435e0bc3d4af0eee349e/index.js#L1

I suggest using something like https://www.npmjs.com/package/patch-package. yarn and pnpm have this feature built in, this is all mentioned in the readme for patch-package.

leumasme commented 1 year ago

this has been addressed

For bundlers that do at least very basic dynamic import tracking, I believe the issue would persist. Since bundlers can not know what the value of the environment variable "FLUENTFFMPEG_COV" is at runtime, they will try to bundle both the import for ./lib/fluent-ffmpeg as well as ./lib-cov/fluent-ffmpeg. Since lib-cov does not exist, this fails.
The solution is to tell your bundler to treat process.env.FLUENTFFMPEG_COV as some given constant value at bundle time.
If you don't know how to configure your bundler to treat the env var as a constant, patching the package is a fine solution since it doesn't look like this package will get updated anymore anyway.

subvertallchris commented 1 year ago

A simple patch using patch-package fixes this easily and reliably. Follow the instructions in the repo to install that and patch node_modules/fluent-ffmpeg/index.js so it only requires lib/fluent-ffmpeg.

diff --git a/node_modules/fluent-ffmpeg/index.js b/node_modules/fluent-ffmpeg/index.js
index 04e594c..68a1522 100644
--- a/node_modules/fluent-ffmpeg/index.js
+++ b/node_modules/fluent-ffmpeg/index.js
@@ -1 +1 @@
-module.exports = process.env.FLUENTFFMPEG_COV ? require('./lib-cov/fluent-ffmpeg') : require('./lib/fluent-ffmpeg');
+module.exports = require('./lib/fluent-ffmpeg');
fabianwohlfart commented 11 months ago

Also stumbled upon this in a complete different setup (nuxt + layers + vite/rollup)

pirmax commented 8 months ago

@pabloVoorvaart Thanks, I use this config since I discover your response, but I've this error when I build the project :


Critical dependency: the request of a dependency is an expression

Import trace for requested module:
./node_modules/fluent-ffmpeg/lib/options/misc.js
./node_modules/fluent-ffmpeg/lib/fluent-ffmpeg.js
./node_modules/fluent-ffmpeg/index.js
./lib/ffmpeg.ts
./actions/index.ts
./app/(app)/(home)/page.tsx```