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

Reference error while building in azure pipeline #120

Open
JoelGeorge693 opened this issue Sep 11, 2024 · 13 comments
Open

Reference error while building in azure pipeline #120

JoelGeorge693 opened this issue Sep 11, 2024 · 13 comments
Labels
bug Something isn't working

Comments

@JoelGeorge693
Copy link

ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/home/vsts/work/1/s/node_modules/json-edit-react/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///home/vsts/work/1/s/node_modules/json-edit-react/build/index.cjs.js:1:20
at ModuleJob.run (node:internal/modules/esm/module_job:234:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:473:24)

I am facing this error when I am my azure pipeline is building the application. It would be of great help if someone could guide me to a solution.

@JoelGeorge693 JoelGeorge693 added the bug Something isn't working label Sep 11, 2024
@CarlosNZ
Copy link
Owner

Are you using the latest version (1.16.0) ? If so, can you try with one of the previous versions (1.15.x) ?

I made a small change to the build process that may have caused this, so if you could let me know what happens with an earlier version, that'd be handy thanks.

@JoelGeorge693
Copy link
Author

No, I am not using the latest version I am using 1.13.1. It was working till the 9th of this month started to have an issue since the 10th. If this helps.

@CarlosNZ
Copy link
Owner

That's odd, because /home/vsts/work/1/s/node_modules/json-edit-react/package.json' contains "type": "module". -- it only changed to use type: module in the very latest release.

You might be able to import the .cjs build directly, if that helps?

import {JsonEditor} from 'json-edit-react/build/index.cjs'

I don't know much about Azure pipelines, but I do suspect that the build process might be pulling in the latest version. Can you explicitly specify a max version in your package.json?

@JoelGeorge693
Copy link
Author

Yes, maybe you're right about the pulling of latest version I'll try adding a strict version and let you know. Also, if that doesn't work I'll try the direct import.

@JoelGeorge693
Copy link
Author

Thanks a lot, you're a life saver, restricting it to a strict version worked.
Have a nice day.

@CarlosNZ
Copy link
Owner

Good to hear. I've just published a new version (1.16.1) with explicit exports specified in package.json, so maybe that will help?

I'm keen for this to work seamlessly in as many environments as possible, so I'll keep trying to make it as flexible as possible, so please post again if you have trouble with a specific version.

@MattChowski
Copy link

After updating to 1.16.1 I get Module not found: Error: Can't resolve 'react/jsx-runtime' for this package :/. If I revert to 1.13.1 all is good

@MattChowski
Copy link

If i try your workaround import {JsonEditor} from 'json-edit-react/build/index.cjs', it works but I lose all typescript types and I can't ts-ignore everything

@CarlosNZ
Copy link
Owner

After updating to 1.16.1 I get Module not found: Error: Can't resolve 'react/jsx-runtime' for this package :/. If I revert to 1.13.1 all is good

If you wouldn't mind, would you be able to go back through the versions from 1.16.1 to see where the problem came in? I'd like to pin it down exactly.

@CarlosNZ
Copy link
Owner

@MattChowski I've removed the type: module in 1.16.3. Can you confirm that version works for you?

@CarlosNZ CarlosNZ reopened this Sep 14, 2024
@CarlosNZ
Copy link
Owner

@MattChowski @JoelGeorge693 Can you try with v1.17.2 and see if it's working for you?

If not, would you mind sharing your repo (or an equivalent repo) so I can check out the problem for myself?

@MattChowski
Copy link

@CarlosNZ Unfortunately I am unable to test this at the moment. We needed a really performant solution for the JSON viewer as our jsons can be huge, so we decided to build our own, optimized for our needs.

Nevertheless this library is great and is better than any other json editor i've seen!

@CarlosNZ
Copy link
Owner

@CarlosNZ Unfortunately I am unable to test this at the moment. We needed a really performant solution for the JSON viewer as our jsons can be huge, so we decided to build our own, optimized for our needs.

All good, just out of interest how big are we talking?

Nevertheless this library is great and is better than any other json editor i've seen!

Thank you 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants