node-mysql2
node-mysql2 copied to clipboard
On Node 12.8 failing at runtime - missing ./lib/constants/types export
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?
I could create the PR#https://github.com/sidorares/node-mysql2/pull/1225 for this request. Please check.
@sidorares Is this really necessary?
@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 )
@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?