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:

  1. added dependency to my project’s package.json
  2. “dependencies”: { … “sip.js”: “0.19.0”, … },
  3. yarn
  4. 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

Commits related to this issue

Most upvoted comments

Pushed fix to main branch here 930462fbf3bbbc7f04202ff00645672dfdbb912f

Would welcome any feedback and/or testing.

  1. Using TypeScript 4.8 for development
  2. With "type": "module" in package.json
  3. Using NodeNext for TypeScript compiler options module and moduleResolution
  4. Added .js extensions to all imports
  5. Only index.js files now import index.js files
  6. Replaced all imports of index.js in general files with imports of the exact file required
  7. Removed double import of the grammar directory (was imported by index.js and core/messages/index.js)
  8. Tested importing into node.js application
  9. Tested importing into HTML page with script tag specifying type="module"
  10. Tested packing with webpack without using the 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 eject and then apply this patch:

diff --git a/config/webpack.config.js b/config/webpack.config.js
index 6b4a4cd..3b29fe5 100644
--- a/config/webpack.config.js
+++ b/config/webpack.config.js
@@ -343,6 +343,9 @@ module.exports = function (webpackEnv) {
           exclude: /@babel(?:\/|\\{1,2})runtime/,
           test: /\.(js|mjs|jsx|ts|tsx|css)$/,
           loader: require.resolve('source-map-loader'),
+          resolve: {
+            fullySpecified: false,
+          }
         },
         {
           // "oneOf" will traverse all following loaders until one will

(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!