When it comes to programming languages, NestJs utilizes ES6, ES7, and ES8, while Firebase Functions seems to be stuck at Node v.6.11.
I made an attempt to create a webpack configuration file with Babel in order to transpile both my files and the node_modules to match Node v6.11. However, I encountered difficulties during deployment due to a syntax error caused by an async function within the @nestjs/common/interceptors/file-fields.interceptor.js file.
⚠ functions[api]: Deployment error.
Function load error: Code in file dist/index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/node_modules/@nestjs/common/interceptors/file-fields.interceptor.js:10
async intercept(context, call$) {
^^^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/user_code/node_modules/@nestjs/common/interceptors/index.js:6:10)
Below is the content of my webpack.config.js file:
'use strict';
const nodeExternals = require('webpack-node-externals');
module.exports = {
entry: './src/server.ts',
output: {
filename: 'index.js',
libraryTarget: 'this'
},
target: 'node',
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
"targets": {
"node": "6.11.1"
}
},
'@babel/stage-0'
]
],
plugins: [require('@babel/plugin-transform-async-to-generator')]
}
},
{
loader: 'ts-loader',
options: {
transpileOnly: true
}
}
]
},
{
test: /\.js$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
"targets": {
"node": "6.11.1"
}
},
'@babel/stage-0'
]
],
plugins: [require('@babel/plugin-transform-async-to-generator')]
}
}
]
}
]
},
resolve: {
extensions: [ '.ts', '.tsx', '.js' ]
},
externals: [nodeExternals()]
};
This is my tsconfig.json file for reference:
{
"compilerOptions": {
"lib": ["es6", "es2015.promise"],
"module": "commonjs",
"noImplicitAny": false,
"outDir": "",
"sourceMap": true,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowJs": true,
"target": "es6",
"typeRoots": [
"node_modules/@types"
]
},
"include": [
"src/**/*.ts",
"spec/**/*.ts"
],
"exclude": [
"**/*.spec.ts"
]
}
What might be causing this issue?