documentation icon indicating copy to clipboard operation
documentation copied to clipboard

MODULE_NOT_FOUND, `jsx` Extensions & Exports

Open iammerrick opened this issue 4 years ago • 1 comments

Input Code

(Where MyInput is a file named MyInput.jsx)

// index.js
export { Something } from 'MyInput';

Output Error

{ Error: Cannot find module '/Users/merrick/Developer/webflow/packages/systems/wfdl/MyInput'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.resolve (internal/modules/cjs/helpers.js:33:19)
    at getCachedData (/Users/merrick/Developer/webflow/node_modules/documentation/src/extractors/exported.js:179:20)
    at findExportDeclaration (/Users/merrick/Developer/webflow/node_modules/documentation/src/extractors/exported.js:208:15)
    at ExportDeclaration.specifiers.forEach.specifier (/Users/merrick/Developer/webflow/node_modules/documentation/src/extractors/exported.js:110:25)
    at Array.forEach (<anonymous>)
    at ExportDeclaration (/Users/merrick/Developer/webflow/node_modules/documentation/src/extractors/exported.js:97:20)
    at NodePath._call (/Users/merrick/Developer/webflow/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (/Users/merrick/Developer/webflow/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/Users/merrick/Developer/webflow/node_modules/@babel/traverse/lib/path/context.js:88:12) code: 'MODULE_NOT_FOUND' }

    at ChildProcess.exithandler (child_process.js:294:12)
    at ChildProcess.emit (events.js:203:15)
    at maybeClose (internal/child_process.js:982:16)
    at Socket.stream.socket.on (internal/child_process.js:389:11)
    at Socket.emit (events.js:198:13)
    at Pipe._handle.close (net.js:607:12)
  • What version of documentation.js are you using?: 12.1.4
  • How are you running documentation.js (on the CLI, Node.js API, Grunt, other?): CLI (readme)

I believe the issue is that documentation uses require.resolve for computing exports in certain cases, require.resolve doesn't support the extensions argument and so if you are doing a named export for a file with a unique extension, the resolution doesn't work. :-( https://github.com/documentationjs/documentation/blob/master/src/extractors/exported.js#L179

This can be worked around by providing an explicit extension:

// index.js
export { Something } from 'MyInput.jsx';

But that isn't an option for our current code.

iammerrick avatar Mar 05 '20 18:03 iammerrick

Yep, this'll necessitate switching away from require.resolve, maybe using resolve instead in this case.

tmcw avatar Nov 14 '20 21:11 tmcw