janniks / basetag

⚾️ A better way to import local NodeJS modules
MIT License
37 stars 3 forks source link

Does not work with ES6 import #20

Closed jdhiro closed 3 years ago

jdhiro commented 3 years ago

For reasons, I'm not clear on yet, this does not seem to work with ES6 imports on Node 14.

For example, this does not work: import db from '$/lib/db.js'

But this does: const db = require('$/lib/db')

The resulting error looks like this:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '$' imported from /Users/jd/dev/my-app/my-file.mjs
    at packageResolve (internal/modules/esm/resolve.js:655:9)
    at moduleResolve (internal/modules/esm/resolve.js:696:18)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11)
    at Loader.resolve (internal/modules/esm/loader.js:85:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:229:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:51:40)
    at link (internal/modules/esm/module_job.js:50:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

At a high level, it looks like Node might be resolving packages for an import in a completely different fashion, perhaps making basetag incompatible. Or I'm missing something.

janniks commented 3 years ago

This is strange, we are testing on Node v14 with imports.

Can you send me some details on your system and exact Node version number – will try to reproduce...

coolaj86 commented 3 years ago

Also, double check that node_modules/$ exists. It's deleted every time you run npm install rather than npm ci.

I've got a PR in #21 as a partial fix for that specific issue.

jdhiro commented 3 years ago

@janniks I'm not yet sure what changed my side, but it seems to be working fine in imports now. I did uninstall and reinstall basetag when I was having issues even with require imports.

I'm currently running v14.15.0

jdhiro commented 3 years ago

Also, double check that node_modules/$ exists. It's deleted every time you run npm install rather than npm ci.

That's what led me to do the uninstall/reinstall. Thank you!