SIP.js: ES Module not compliant with import statements missing file extensions
Describe the bug ES Module not compliant with import statements missing file extensions.
Logs ERROR in ./node_modules/sip.js/lib/index.js 2:0-44 Module not found: Error: Can’t resolve ‘./version’ in ‘/Users/msaavedra/cirkelco/gitlab/colabrie-desktop/node_modules/sip.js/lib’ Did you mean ‘version.js’? BREAKING CHANGE: The request ‘./version’ failed to resolve only because it was resolved as fully specified (probably because the origin is a ‘.mjs’ file or a '.js’ file where the package.json contains ‘“type”: “module”’). The extension in the request is mandatory for it to be fully specified. Add the extension to the request. @ dll renderer renderer[8]
ERROR in ./node_modules/sip.js/lib/index.js 7:0-22 Module not found: Error: Can’t resolve ‘./api’ in ‘/Users/msaavedra/cirkelco/gitlab/colabrie-desktop/node_modules/sip.js/lib’ Did you mean ‘index.js’? BREAKING CHANGE: The request ‘./api’ failed to resolve only because it was resolved as fully specified (probably because the origin is a ‘.mjs’ file or a '.js’ file where the package.json contains ‘“type”: “module”’). The extension in the request is mandatory for it to be fully specified. Add the extension to the request. @ dll renderer renderer[8]
ERROR in ./node_modules/sip.js/lib/index.js 9:0-26 Module not found: Error: Can’t resolve ‘./grammar’ in ‘/Users/msaavedra/cirkelco/gitlab/colabrie-desktop/node_modules/sip.js/lib’ Did you mean ‘index.js’? BREAKING CHANGE: The request ‘./grammar’ failed to resolve only because it was resolved as fully specified (probably because the origin is a ‘.mjs’ file or a '.js’ file where the package.json contains ‘“type”: “module”’). The extension in the request is mandatory for it to be fully specified. Add the extension to the request. @ dll renderer renderer[8]
ERROR in ./node_modules/sip.js/lib/index.js 11:0-31 Module not found: Error: Can’t resolve ‘./core’ in ‘/Users/msaavedra/cirkelco/gitlab/colabrie-desktop/node_modules/sip.js/lib’ Did you mean ‘index.js’? BREAKING CHANGE: The request ‘./core’ failed to resolve only because it was resolved as fully specified (probably because the origin is a ‘.mjs’ file or a '.js’ file where the package.json contains ‘“type”: “module”’). The extension in the request is mandatory for it to be fully specified. Add the extension to the request. @ dll renderer renderer[8]
ERROR in ./node_modules/sip.js/lib/index.js 14:0-38 Module not found: Error: Can’t resolve ‘./platform/web’ in ‘/Users/msaavedra/cirkelco/gitlab/colabrie-desktop/node_modules/sip.js/lib’ Did you mean ‘index.js’? BREAKING CHANGE: The request ‘./platform/web’ failed to resolve only because it was resolved as fully specified (probably because the origin is a ‘.mjs’ file or a '.js’ file where the package.json contains ‘“type”: “module”’). The extension in the request is mandatory for it to be fully specified. Add the extension to the request. @ dll renderer renderer[8]
To Reproduce (if possible) Steps to reproduce the behavior:
- added dependency to my project’s package.json
- “dependencies”: { … “sip.js”: “0.19.0”, … },
yarn- See error
Expected behavior Should compile without errors
Observed behavior Sip.js clearly uses ES Modules as of recently, but doesn’t specify import file extensions
Environment Information
- Node.js 15.8.0
- Electron 11.2.3
- React 17.0.1
Additional context https://nodejs.org/api/packages.html#packages_package_json_and_file_extensions
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 18
Pushed fix to main branch here 930462fbf3bbbc7f04202ff00645672dfdbb912f
Would welcome any feedback and/or testing.
"type": "module"inpackage.jsonNodeNextfor TypeScript compiler optionsmoduleandmoduleResolution.jsextensions to all importsindex.jsfiles now importindex.jsfilesindex.jsin general files with imports of the exact file requiredgrammardirectory (was imported byindex.jsandcore/messages/index.js)type="module"resolve: { fullySpecified: false }I think it’s backward compatible with 0.20.x (I’ve dropped it into a few existing projects without any issues), but imagine there are custom build setups with workarounds related to this issue which now might break? I know the idea is addressing this issue will make the need for that kind of thing go away, but suppose I can imagine not being able to drop this in for some setups?
Again, any feedback and/or testing welcome - I’d like to get this right this time around and put it behind us.
This is still an issue for anyone trying to install and use sip.js in a default React app created by CRA with TS template.
For now, the workaround for me was
npm run ejectand then apply this patch:(And this is the first time I needed to eject CRA in 4 years.)
Added to main branch and queued up to go out soon in next release - 0.21.0.
Unfortunately, it also makes the packace unusable for us that you cannot import it in a vanilla Node.js project without workarounds. To me, it sounds like a pretty urgent problem for an npm package. Hopefully there is a neat solution!