node-mysql2 icon indicating copy to clipboard operation
node-mysql2 copied to clipboard

On Node 12.8 failing at runtime - missing ./lib/constants/types export

Open rbotla opened this issue 4 years ago • 4 comments

We are getting the following error on Node 12.8.

{"timestamp":"2020-10-05T16:00:58.348Z","error":{"code":"ERR_PACKAGE_PATH_NOT_EXPORTED"},"level":"error","message":"uncaughtException: Package subpath './lib/constants/types' is not defined by \"exports\" in /home/ec2-user/ucep-api/node_modules/mysql2/package.json\nError [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/constants/types' is not defined by \"exports\" in /home/ec2-user/ucep-api/node_modules/mysql2/package.json\n    at applyExports (internal/modules/cjs/loader.js:490:9)\n    at resolveExports (internal/modules/cjs/loader.js:506:23)\n    at Function.Module._findPath (internal/modules/cjs/loader.js:634:31)\n    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:952:27)\n    at Function.Module._load (internal/modules/cjs/loader.js:841:27)\n    at Module.require (internal/modules/cjs/loader.js:1025:19)\n    at require (internal/modules/cjs/helpers.js:72:18)\n    at Object.<anonymous> (/home/ec2-user/ucep-api/dist/middleware/field.js:20:14)\n    at Module._compile (internal/modules/cjs/loader.js:1137:30)\n    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)","stack":"Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/constants/types' is not defined by \"exports\" in /home/ec2-user/ucep-api/node_modules/mysql2/package.json\n    at applyExports (internal/modules/cjs/loader.js:490:9)\n    at resolveExports (internal/modules/cjs/loader.js:506:23)\n    at Function.Module._findPath (internal/modules/cjs/loader.js:634:31)\n    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:952:27)\n    at Function.Module._load (internal/modules/cjs/loader.js:841:27)\n    at Module.require (internal/modules/cjs/loader.js:1025:19)\n    at require (internal/modules/cjs/helpers.js:72:18)\n    at Object.<anonymous> (/home/ec2-user/ucep-api/dist/middleware/field.js:20:14)\n    at Module._compile (internal/modules/cjs/loader.js:1137:30)\n    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)","exception":true,"date":"Mon Oct 05 2020 16:00:58 GMT+0000 (Coordinated Universal Time)","process":{"pid":9639,"uid":500,"gid":500,"cwd":"/home/ec2-user/ucep-api","execPath":"/home/ec2-user/ucep-api/node_modules/node/bin/node","version":"v12.18.4","argv":["/home/ec2-user/ucep-api/node_modules/node/bin/node","/home/ec2-user/ucep-api/dist/bin/www"],"memoryUsage":{"rss":54689792,"heapTotal":29102080,"heapUsed":13521360,"external":1552060,"arrayBuffers":253773}},"os":{"loadavg":[0.08447265625,0.0771484375,0.19287109375],"uptime":248596},"trace":[{"column":9,"file":"internal/modules/cjs/loader.js","function":"applyExports","line":490,"method":null,"native":false},{"column":23,"file":"internal/modules/cjs/loader.js","function":"resolveExports","line":506,"method":null,"native":false},{"column":31,"file":"internal/modules/cjs/loader.js","function":"Module._findPath","line":634,"method":"_findPath","native":false},{"column":27,"file":"internal/modules/cjs/loader.js","function":"Module._resolveFilename","line":952,"method":"_resolveFilename","native":false},{"column":27,"file":"internal/modules/cjs/loader.js","function":"Module._load","line":841,"method":"_load","native":false},{"column":19,"file":"internal/modules/cjs/loader.js","function":"Module.require","line":1025,"method":"require","native":false},{"column":18,"file":"internal/modules/cjs/helpers.js","function":"require","line":72,"method":null,"native":false},{"column":14,"file":"/home/ec2-user/ucep-api/dist/middleware/field.js","function":null,"line":20,"method":null,"native":false},{"column":30,"file":"internal/modules/cjs/loader.js","function":"Module._compile","line":1137,"method":"_compile","native":false},{"column":10,"file":"internal/modules/cjs/loader.js","function":"Module._extensions..js","line":1157,"method":".js","native":false}],"APP_ID":2163,"region":"us-east-1a"}

We could fix the issue if we add the following line in mysql2 package.json "./lib/constants/types": "./lib/constats/types.js" under exports section. Also, attached the snippet with the change. Can someone submit PR and merge the changes soon?

image

rbotla avatar Oct 05 '20 16:10 rbotla

I could create the PR#https://github.com/sidorares/node-mysql2/pull/1225 for this request. Please check.

rbotla avatar Oct 05 '20 16:10 rbotla

@sidorares Is this really necessary?

testn avatar Oct 29 '21 01:10 testn

@testn It might be related to esm support. Haven't used mysql2 myself in esm-only environment but I'd expect that to be more and more popular way to import module over time so keen to support properly for all currently supported versions ( right now v12 - v17 )

sidorares avatar Oct 29 '21 03:10 sidorares

@rbotla I really don't want to expose any internal files and export everything via top level exports. Right now I expect only 2 ways of using the module: import mysql from 'mysql2' and import mysql from 'mysql2/promise'

in what scenarios you see the error you posted?

sidorares avatar Oct 29 '21 03:10 sidorares