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

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

Closed
Jaetoh opened this issue Jul 22, 2016 · 40 comments
Closed

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

Jaetoh opened this issue Jul 22, 2016 · 40 comments

Comments

@Jaetoh
Copy link

Jaetoh commented Jul 22, 2016

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
Copy link
Member

njoyard commented Jul 27, 2016

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
Copy link
Author

Jaetoh commented Jul 27, 2016

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
Copy link

chervox commented Aug 6, 2016

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
Copy link
Author

Jaetoh commented Aug 10, 2016

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

@njoyard
Copy link
Member

njoyard commented Aug 10, 2016

@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.

@njoyard njoyard closed this as completed Aug 10, 2016
@agmcleod
Copy link

agmcleod commented Jan 5, 2017

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

@kus
Copy link

kus commented Jun 1, 2017

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
Copy link

crakjie commented Jun 12, 2017

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

@Jfeng3
Copy link

Jfeng3 commented Jun 15, 2017

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
Copy link

kus commented Jun 16, 2017

@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
Copy link

michaelmaitland commented Apr 15, 2020

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
Copy link

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.

statik added a commit to kindlyops/murderhornet that referenced this issue Feb 18, 2021
fluent-ffmpeg/node-fluent-ffmpeg#573

Signed-off-by: Elliot Murphy <statik@users.noreply.github.com>
@muzammal-murtaza
Copy link

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
Copy link

dancixx commented Mar 31, 2021

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

@sharunspi
Copy link

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
Copy link

max-programming commented Apr 7, 2021

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 😢

haflinger added a commit to haflinger/node-fluent-ffmpeg that referenced this issue Jul 27, 2021
@Losses
Copy link

Losses commented Aug 23, 2021

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
Copy link

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
Copy link

PAXANDDOS commented Jan 29, 2022

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
Copy link

lanly-dev commented Feb 4, 2022

This worked for me:

new EnvironmentPlugin({
  FLUENTFFMPEG_COV: '',
})

@serg06
Copy link

serg06 commented Mar 30, 2022

@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
Copy link

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
Copy link

Tikam02 commented Jul 12, 2022

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

where to add this in React project?

@vikash265
Copy link

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

where to add this in React project?

1 similar comment
@vikash265
Copy link

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

where to add this in React project?

@oakgary
Copy link

oakgary commented Oct 14, 2022

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
Copy link

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
Copy link

while using serverless.

this worked for me!! thanks!

@mcorrigan
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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

@pblvrt
Copy link

pblvrt commented Jul 10, 2023

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
Copy link

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

@McKean
Copy link

McKean commented Aug 3, 2023

For people stumbling over this, this has been addressed but the changes have not been published since:

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

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
Copy link

leumasme commented Aug 4, 2023

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
Copy link

subvertallchris commented Aug 12, 2023

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
Copy link

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

@pirmax
Copy link

pirmax commented Feb 20, 2024

@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```

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