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

Module not found: Can't resolve 'poly-decomp' #981

Closed
steveja42 opened this issue Mar 5, 2021 · 13 comments · Fixed by #995
Closed

Module not found: Can't resolve 'poly-decomp' #981

steveja42 opened this issue Mar 5, 2021 · 13 comments · Fixed by #995

Comments

@steveja42
Copy link

I am seeing this message in the debug output when using matter-js:

./node_modules/.pnpm/[email protected]/node_modules/matter-js/build/matter.js
Module not found: Can't resolve 'poly-decomp' in 'C:\dev\webpranks\node_modules.pnpm\[email protected]\node_modules\matter-js\build'

This is the minimal code to reproduce:

import { Engine, Render, Bodies, World } from "matter-js";
const engine = Engine.create();
@liabru
Copy link
Owner

liabru commented Mar 6, 2021

Thanks for reporting, can you give more information on the environment you're running this in?

Any build tools, node version, npm version, browser etc. and what program specifically is the error message coming from?

@steveja42
Copy link
Author

I think the error message is from typescript. It is a .ts file. I am using create-react-app build and node ver 14.15.1. and I'm using pnpm ver 5.18.3 instead of npm. When I do yarn start and then change the .ts file it says:

Compiled with warnings.

./node_modules/.pnpm/[email protected]/node_modules/matter-js/build/matter.js
Module not found: Can't resolve 'poly-decomp' in 'C:\dev\webpranks\node_modules.pnpm\[email protected]\node_modules\matter-js\build'

It seems like matter.js is still functioning anyway.

@treardon17
Copy link

I am also getting this error message

@liabru
Copy link
Owner

liabru commented Mar 9, 2021

@treardon17 could you please also provide the above requested info? Thanks!

@treardon17
Copy link

@liabru sure thing! sorry I didn't include more details to begin with...

node: v12.15.0
yarn: 1.23.0-20200928.1349

Minimum code to reproduce:

import Matter from 'matter-js';

Causes this warning during my build process:

WARNING in /project/node_modules/matter-js/build/matter.js
Module not found: Error: Can't resolve 'poly-decomp' in '/project/node_modules/matter-js/build'

Doing yarn add poly-decomp fixes the issue, but if poly-decomp is a required dependency shouldn't it be in the package.json dependencies?

@liabru
Copy link
Owner

liabru commented Mar 9, 2021

@treardon17 thanks what build tools are you using here?

poly-decomp is an optional dependency that is required at runtime on a specific function, the problem is that build tools don't seem to understand dynamic imports.

@treardon17
Copy link

@liabru ahh that makes sense. I'm working on a package that's being consumed by another application. The package is built with rollup 2.40.x, and the application that's consuming the built package is using webpack 4.44.x

@liabru
Copy link
Owner

liabru commented Mar 9, 2021

@treardon17 can you tell which program the error message is originating from specifically? I'm using Webpack and it seems to be fine, my guess is rollup? Also is this with matter-js 0.16.1?

@treardon17
Copy link

treardon17 commented Mar 9, 2021

@liabru the error is coming from the webpack build, but I'm wondering if the issue is in the output of the rollup build...

and yes, this is with matter-js: 0.16.1 😄

@liabru
Copy link
Owner

liabru commented Mar 13, 2021

To be clear for anyone still seeing this issue you can avoid the warning for the moment by just installing the module via npm install poly-decomp --save (even though it's technically optional).

The problem seems to be external - build tools don't appear to handle conditional require calls as expected, which I'm not sure there's a fix for (unless anybody has any ideas).

So unfortunately there may need to be a breaking change coming (which I've been trying to avoid): removing this require all together and asking users to pass the decomp module as an argument (or set the global). I'm sure that will create just as much confusion as this error though.

@liabru liabru added the bug label Mar 13, 2021
@treardon17
Copy link

@liabru it seems like having users pass the dependency would be a good direction. It would make the poly-decomp module feel more like a plugin.

@liabru
Copy link
Owner

liabru commented Apr 11, 2021

As of release 0.17.0 the approach is now to use the new function Common.setDecomp, which you can see in use on the concave example.

The window.decomp global is also still supported, but it is still advised to specifically use Common.setDecomp where possible.

There is no longer any require usage meaning bundlers should work fine, so considering the issue now resolved but feel free to comment still if needed. Thanks again for reporting.

@fccm2
Copy link

fccm2 commented Dec 21, 2023

Could you explain how to set the poly-decomp dependency, Common.setDecomp(require('poly-decomp')) doesn't work, I get an error with require in my web-browser. (And the examples are not readable because it's minified.)

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

Successfully merging a pull request may close this issue.

4 participants