-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic require of "path" is not supported #3324
Comments
This issue is already tracked here: #1921 In summary, this runtime error is caused by bundling CJS libraries into ESM context (i.e. bundle I would still suggest you to exclude these dependencies from your bundle with |
@hyrious will work if i deploy the code? |
Making this work with * firebase functions * esm modules, esp with "type":"modules" in package.json * typescript is hilariously hard. Firebase functions do not understand esm modules. This causes their preprocessor to blow up if you use them. There is a workaround here: firebase/firebase-tools#2994 (comment) that uses esbuild to bundle all of the code into one huge index.js that papers over all the preprocessing issues. It also does some magic with package.json and the npm-run-all package to ensure all of esbuild, tsc, and firebase run in parallel so that changing a typescript source file results in an actual behavior change to a running function emulator. However, this is still not sufficient because esbuild has decided to bundle everything in devDependencies and dependencies into the index.js. This will pull in old commonJS packages but attempt to run that syntax in an ESM environment which causes a cryptic "Dynamic require of 'something' is not supported" This will send you down rabbit holes of trying to fix tsc config because it looks like you are exporting the wrong module loading type..which will lead you to try setting tsconfig's module to "nodenext"...which confusing *requires* you to put .js after all your relative path imports even if the source file is .ts. This is confusing as heck. But the real problem is you need to exclude packages from esbuild: evanw/esbuild#3324 (comment) And now everything will run. Howeever, it means you have to ensure the deploy picks up your node_modules.... ugh.
Making this work with * firebase functions * esm modules, esp with "type":"modules" in package.json * typescript is hilariously hard. Firebase functions do not understand esm modules. This causes their preprocessor to blow up if you use them. There is a workaround here: firebase/firebase-tools#2994 (comment) that uses esbuild to bundle all of the code into one huge index.js that papers over all the preprocessing issues. It also does some magic with package.json and the npm-run-all package to ensure all of esbuild, tsc, and firebase run in parallel so that changing a typescript source file results in an actual behavior change to a running function emulator. However, this is still not sufficient because esbuild has decided to bundle everything in devDependencies and dependencies into the index.js. This will pull in old commonJS packages but attempt to run that syntax in an ESM environment which causes a cryptic "Dynamic require of 'something' is not supported" This will send you down rabbit holes of trying to fix tsc config because it looks like you are exporting the wrong module loading type..which will lead you to try setting tsconfig's module to "nodenext"...which confusing *requires* you to put .js after all your relative path imports even if the source file is .ts. This is confusing as heck. But the real problem is you need to exclude packages from esbuild: evanw/esbuild#3324 (comment) And now everything will run. Howeever, it means you have to ensure the deploy picks up your node_modules.... ugh. Oh...and jest's setup requires you to NOT use verbatimModuleSyntax otherwise you cannot import typescript types since its config file is a CommonJs setup and the import syntax is ESM.
Making this work with * firebase functions * esm modules, esp with "type":"modules" in package.json * typescript is hilariously hard. Firebase functions do not understand esm modules. This causes their preprocessor to blow up if you use them. There is a workaround here: firebase/firebase-tools#2994 (comment) that uses esbuild to bundle all of the code into one huge index.js that papers over all the preprocessing issues. It also does some magic with package.json and the npm-run-all package to ensure all of esbuild, tsc, and firebase run in parallel so that changing a typescript source file results in an actual behavior change to a running function emulator. However, this is still not sufficient because esbuild has decided to bundle everything in devDependencies and dependencies into the index.js. This will pull in old commonJS packages but attempt to run that syntax in an ESM environment which causes a cryptic "Dynamic require of 'something' is not supported" This will send you down rabbit holes of trying to fix tsc config because it looks like you are exporting the wrong module loading type..which will lead you to try setting tsconfig's module to "nodenext"...which confusing *requires* you to put .js after all your relative path imports even if the source file is .ts. This is confusing as heck. But the real problem is you need to exclude packages from esbuild: evanw/esbuild#3324 (comment) And now everything will run. Howeever, it means you have to ensure the deploy picks up your node_modules.... ugh. Oh...and jest's setup requires you to NOT use verbatimModuleSyntax otherwise you cannot import typescript types since its config file is a CommonJs setup and the import syntax is ESM.
It depends on your deployment environment, if you are only sending the build output upstream then no - it won't. |
im trying to build and run express server code
entry/server.js
:entry/build.js
:package.json
:when i do
npm run dev
i get this error:The text was updated successfully, but these errors were encountered: