0beqz / screen-space-reflections

Implements Screen Space Reflections in three.js
https://screen-space-reflections.vercel.app/
MIT License
550 stars 44 forks source link

Cannot use import statement outside a module #5

Closed benjaminmiles closed 2 years ago

benjaminmiles commented 2 years ago

First off, incredible work here! We are using @react-postprocessing inside of a Jenkins build pipeline, and the following error just started showing up and breaking the build process. Looks like @react-postprocessing started including the SSRPass as part of their package.

/node_modules/screen-space-reflections/ScreenSpaceReflections.js:25
import { Pass, RenderPass, DepthPass, KernelSize, KawaseBlurPass } from 'postprocessing';

SyntaxError: Cannot use import statement outside a module
0beqz commented 2 years ago

Thanks, I appreciate it. That's weird, I think that could be due to the package.json of the module now that I compared it with the package.json of other modules that also use the import statement (e.g. postprocessing.js). So can you navigate to node_modules/screen-space-reflections/package.json in your project to open the package.json file of the module? From there change the main attribute to module.

The attribute should be here in the package.json: https://github.com/0beqz/screen-space-reflections/blob/main/dist/package.json#L5 Just change it to "module" like it is here for example: https://github.com/pmndrs/postprocessing/blob/main/package.json#L7

If that still doesn't work, try to add type: "module" to the package.json. Let me know if that fixes the issue.

drcmda commented 2 years ago

ah yes, i think it should be "module". if you want i can make a PR for module and cjs support, for instance i could do it like this: https://github.com/pmndrs/tunnel-rat do you want simple annotational typescript support btw? i don't use ts either but i have it in most libs because that way IDE's autocomplete and show the docs on hover.

0beqz commented 2 years ago

Yeah sure, I'd appreciate if you could make a PR to add CJS support and TypeScript annotations.

benjaminmiles commented 2 years ago

Thank you both. Happy to test and confirm once the PR is merged!

drcmda commented 2 years ago

this should work: https://github.com/0beqz/screen-space-reflections/pull/6

0beqz commented 2 years ago

It's merged. You can test now if the error is gone

vradionovskii commented 2 years ago

Still doesn't work in next.js

drcmda commented 2 years ago

could you publish it @0beqz ? im getting complaints for react-pp as it has ssr in dependencies. without "module" these systems treat it as a regular js file that can't have imports in them.

0beqz commented 2 years ago

It's published now, version 1.0.8