I am currently working on creating an internal library for my workplace.
Everything seems to be going smoothly until I try to use it in another project. It appears that the file extension in all of the import
statements has disappeared during the npm pack
phase.
To illustrate, the statement:
import * as Account from './modules/account.js'
turns into:
import * as Account from './modules/account'
This change causes the import to fail.
Initially, I thought this issue might have occurred because I used the .js
extension instead of .mjs
, but even switching to .mjs
produces the same problem.
main.js
import * as Account from './modules/account.js'
Account.secretSquirrel().then( data => console.log( 'inspector gadget', data ) );
node version
v16.15.0
package.json (confidential information hidden)
{
"name": "@Nunya",
"version": "0.0.0",
"description": "Nunya",
"private": true,
"main": "./lib/main.js",
"scripts": {
"build": "npm run pack",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "Nunya.git"
},
"author": "Nunya",
"license": "ISC",
"type": "module",
"exports": {
".": {
"require": "./lib/main.js",
"default": "./lib/main.js"
},
"./Account": "./lib/modules/account.js"
}
}
Based on my analysis, this discrepancy should not be occurring. I am unsure how to address it