direct deep imports prefers .js over .mjs files
Describe the bug
serverPluginModuleResolve
currently prefers .js
files over .mjs
files when using direct deep imports.
A quick&dirty fix would be to replace the .js
with an .mjs
extension and serve that file if it exists. Not sure what a proper solution would be.
Reproduction
Add the following import to a basic vite setup:
import { Kinds } from 'graphql/language/kinds';
(See https://github.com/sventschui/vite-mjs-repro)
System Info
- required
vite
version: `=> 0.14.2 - required Operating System: OS X
- required Node version: 13.12.0
Logs (Optional if provided reproduction)
Browser console:
Uncaught SyntaxError: The requested module '/@modules/graphql/language/kinds' does not provide an export named 'Kinds'
Dug a bit into this and the origin is in resolve-from
. Internally it calls a private node resolution method:
Module._resolveFilename(moduleId, {
id: fromFile,
filename: fromFile,
paths: Module._nodeModulePaths(fromDirectory)
});
Trouble is that node has no knowledge of the module
field in package.json
. It's something exclusively used by bundlers.