From 80eadda87cfe38273f605fbc4e49d0d37945d61f Mon Sep 17 00:00:00 2001 From: Charlie Ruan <53290280+CharlieFRuan@users.noreply.github.com> Date: Tue, 14 May 2024 01:12:32 -0400 Subject: [PATCH] [Next][Fix] Remove require() in index.js for scriptDir --- cleanup-index-js.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cleanup-index-js.sh b/cleanup-index-js.sh index 9e7f9395..3209000b 100755 --- a/cleanup-index-js.sh +++ b/cleanup-index-js.sh @@ -4,6 +4,12 @@ sed -e s/"const{createRequire:createRequire}=await import('module');"//g -i .backup lib/index.js sed -e s/"const{createRequire:createRequire}=await import('module');"//g -i .backup lib/index.js.map +# Replace string "new (require('u' + 'rl').URL)('file:' + __filename).href" with "MLC_DUMMY_PATH" +# This is required for building nextJS projects -- its compile time would complain about `require()` +# See https://github.com/mlc-ai/web-llm/issues/383 and the fixing PR's description for more. +sed -e s/"new (require('u' + 'rl').URL)('file:' + __filename).href"/"\"MLC_DUMMY_PATH\""/g -i .backup lib/index.js +sed -e s/"new (require('u' + 'rl').URL)('file:' + __filename).href"/"\"MLC_DUMMY_PATH\""/g -i .backup lib/index.js.map + # Cleanup backup files rm lib/index.js.backup rm lib/index.js.map.backup \ No newline at end of file