kevin940726 / remark-code-import

📝 Populate code blocks from files
https://npm.im/remark-code-import
MIT License
62 stars 11 forks source link

Reading from "node:fs" is not handled by plugins (Unhandled scheme). #22

Closed jsinglet closed 2 years ago

jsinglet commented 2 years ago

I was attempting to use this plugin with Next.js 12.0.7 -- however, when I add it I get the following error:

[dev:*next] Module build failed: UnhandledSchemeError: Reading from "node:fs" is not handled by plugins (Unhandled scheme).
[dev:*next] Webpack supports "data:" and "file:" URIs by default.
[dev:*next] You may need an additional plugin to handle "node:" URIs.

This is of course coming from this:

import fs from 'node:fs';
import path from 'node:path';
import { EOL } from 'node:os';
import { visit } from 'unist-util-visit';
import stripIndent from 'strip-indent';

I spent a bunch of time trying various solutions with webpack and next -- I see that there is some incompatibility with various versions of webpack and next however I am unable to find a solution.

Filing this here but I would appreciate any insight into getting this plugin working!

kevin940726 commented 2 years ago

The node: scheme is a nodejs standard and is supported (backported) all the way down to v12.

Possible related issues for:

I see that this is still an issue in Next.js. Maybe you can try one of the solutions/workarounds provided in the thread? LMK if it helps 😉.

jsinglet commented 2 years ago

Thanks for the quick response @kevin940726! Sadly, I've tried like every variation of the solutions (and hacks) in those threads with no luck :( Maybe I'm doing something wrong but I even tried the "delete the .next directory" one. Any ideas?

jsinglet commented 2 years ago

Going to close this. I was able to get this working by adapting the plugin code to fit my usecase -- passing in a handle to the fs module is essentially what I had to do. It won't work in general so I don't have anything to contribute back to your plugin.