Deploying MS Teams App to Azure App Service - azure

I have created a simple Teams App using Yeoman Generator and have added a single static tab to my Teams project. I'm trying to deploy this to an Azure App Service. This is the error log from App Service Deployment Center
Failed to load ./.env.
[11:41:54] [Webpack error] multi ./src/app/scripts/client.ts
Module not found: Error: Can't resolve 'D:\home\site\repository/src/app/scripts/client.ts' in 'D:\home\site\repository'
resolve 'D:\home\site\repository/src/app/scripts/client.ts' in 'D:\home\site\repository'
Unhandled rejection [31mError[39m in plugin "[36mwebpack[39m"
using description file: D:\home\site\repository\package.json (relative path: .)
Field 'browser' doesn't contain a valid alias configuration
using description file: D:\home\site\repository\package.json (relative path: ./src/app/scripts/client.ts)
no extension
Field 'browser' doesn't contain a valid alias configuration
Message:
Webpack errors, see log
D:\home\site\repository\src\app\scripts\client.ts doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
D:\home\site\repository\src\app\scripts\client.ts.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
D:\home\site\repository\src\app\scripts\client.ts.tsx doesn't exist
Unhandled rejection [31mError[39m in plugin "[36mwebpack[39m"
Message:
Webpack errors, see log
.js
Field 'browser' doesn't contain a valid alias configuration
D:\home\site\repository\src\app\scripts\client.ts.js doesn't exist
as directory
D:\home\site\repository\src\app\scripts\client.ts doesn't exist
[D:\home\site\repository\src\app\scripts\client.ts]
[D:\home\site\repository\src\app\scripts\client.ts.ts]
[D:\home\site\repository\src\app\scripts\client.ts.tsx]
[D:\home\site\repository\src\app\scripts\client.ts.js]
# multi ./src/app/scripts/client.ts client[0]
[11:41:55] [Webpack error] multi ./src/app/server.ts
Module not found: Error: Can't resolve 'D:\home\site\repository/src/app/server.ts' in 'D:\home\site\repository'
resolve 'D:\home\site\repository/src/app/server.ts' in 'D:\home\site\repository'
using description file: D:\home\site\repository\package.json (relative path: .)
using description file: D:\home\site\repository\package.json (relative path: ./src/app/server.ts)
no extension
D:\home\site\repository\src\app\server.ts doesn't exist
.ts
D:\home\site\repository\src\app\server.ts.ts doesn't exist
.tsx
D:\home\site\repository\src\app\server.ts.tsx doesn't exist
.js
D:\home\site\repository\src\app\server.ts.js doesn't exist
as directory
D:\home\site\repository\src\app\server.ts doesn't exist
[D:\home\site\repository\src\app\server.ts]
[D:\home\site\repository\src\app\server.ts.ts]
[D:\home\site\repository\src\app\server.ts.tsx]
[D:\home\site\repository\src\app\server.ts.js]
# multi ./src/app/server.ts server[0]
[tslint-plugin] Starting linter in separate process...
[tslint-plugin] Starting linter in separate process...
[tslint-plugin] Linting complete.
[tslint-plugin] Linting complete.
[11:42:02] The following tasks did not complete: build, webpack, webpack:client, webpack:server
[11:42:02] Did you forget to signal async completion?
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! emphub#0.0.1 build: `gulp build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the emphub#0.0.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
This is my webpack.config.js file
var webpack = require('webpack');
const Dotenv = require('dotenv-webpack');
var TSLintPlugin = require('tslint-webpack-plugin');
var path = require('path');
var fs = require('fs');
var argv = require('yargs').argv;
var debug = argv.debug !== undefined;
const lint = argv["linting"];
var nodeModules = {};
fs.readdirSync('node_modules')
.filter(function (x) {
return ['.bin'].indexOf(x) === -1;
})
.forEach(function (mod) {
nodeModules[mod] = 'commonjs ' + mod;
});
var config = [{
entry: {
server: [
__dirname + '/src/app/server.ts'
],
},
mode: debug ? 'development' : 'production',
output: {
path: __dirname + '/dist',
filename: '[name].js',
devtoolModuleFilenameTemplate: debug ? '[absolute-resource-path]' : '[]'
},
externals: nodeModules,
devtool: 'source-map',
resolve: {
extensions: [".ts", ".tsx", ".js"],
alias: {}
},
target: 'node',
node: {
__dirname: false,
__filename: false,
},
module: {
rules: [{
test: /\.tsx?$/,
exclude: [/lib/, /dist/],
loader: "ts-loader"
}]
},
plugins: []
},
{
entry: {
client: [
__dirname + '/src/app/scripts/client.ts'
]
},
mode: debug ? 'development' : 'production',
output: {
path: __dirname + '/dist/web/scripts',
filename: '[name].js',
libraryTarget: 'umd',
library: 'emphub',
publicPath: '/scripts/'
},
externals: {},
devtool: 'source-map',
resolve: {
extensions: [".ts", ".tsx", ".js"],
alias: {}
},
target: 'web',
module: {
rules: [{
test: /\.tsx?$/,
exclude: [/lib/, /dist/],
loader: "ts-loader",
options: {
configFile: "tsconfig-client.json"
}
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
loader: 'file-loader?name=public/fonts/[name].[ext]'
}
]
},
plugins: [
new Dotenv({
systemvars: true
})
],
performance: {
maxEntrypointSize: 400000,
maxAssetSize: 400000,
assetFilter: function(assetFilename) {
return assetFilename.endsWith('.js');
}
}
}
];
if (lint !== false) {
config[0].plugins.push(new TSLintPlugin({
files: ['./src/app/*.ts']
}));
config[1].plugins.push(new TSLintPlugin({
files: ['./src/app/scripts/**/*.ts', './src/app/scripts/**/*.tsx']
}));
}
module.exports = config;
Could you please let me know what I am doing wrong? I'm pusing the code using git push azure master from my project root directory

Related

How to fix webpack Error: Cannot find module - on node.js (webpackEmptyContext)

My webpack.config.js is :
const path = require('path');
module.exports = {
entry: './app.ts',
target: 'node',
node: {
__dirname: true
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [ '.tsx', '.ts', '.js' ],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
};
When I build my project and run it I am getting the following error:
(node:51071) UnhandledPromiseRejectionWarning: Error: Cannot find module '../gather/gatherers/css-usage'
at webpackEmptyContext (webpack:///./node_modules/lighthouse/lighthouse-core/config_sync?:2:10)
at Function.requireGathererFr
This error is raised from a 3rd party library I am using - lighthouse.
How to fix this error ?
For target as node, you might have to use this package webpack-node-externals in order to ignore all modules in node_module folder. Then declare as externals:
const nodeExternals = require('webpack-node-externals');
module.exports = {
externals: [nodeExternals()],
// ...
};

Why webpack incorrectly resolve a local path to Javascript file as root path?

I'm using webpack 4.20.0 npm package. One of the dependencies of my dependencies in the npm package mimer. mimer has a file mime.types located in node_modules/mimer/lib/data/mime.types. The package also has a file node_modules/mimer/lib/exec.js which contains the following line:
list: (typeof process !== 'undefined' && process.cwd) ? require('./data/parser')(__dirname + '/data/mime.types') : $_MIMER_DATA_LIST
webpack succeeds to compile my code and I get a bundle but when I run the bundle with node.js I get this error:
Error: ENOENT: no such file or directory, open '//data/mime.types'
I think it occurs as a result of webpack incorrectly providing __dirname value by resolving __dirname as root. Is there a way to solve such an issue in webpack?
This is my webpack config:
const path = require('path')
const webpack = require('webpack')
module.exports = {
mode: 'development',
target: 'node',
context: path.resolve(__dirname),
entry: path.resolve(__dirname, 'src', 'index.js'),
resolve: {
modules: [path.resolve(__dirname, './src'), 'node_modules'],
extensions: ['.js', '.jsx', '.json'],
},
output: {
filename: 'bundle.js',
publicPath: path.resolve(__dirname, 'assets'),
path: path.resolve(__dirname)
},
devtool: 'source-map',
plugins: [
new webpack.IgnorePlugin(/^(hiredis|transifex)$/)
],
module: {
rules: [
{
test: /\.js?$/,
use: {
loader: 'babel-loader',
options: {
rootMode: 'upward'
}
},
include: [
path.resolve(__dirname, 'src')
]
}
]
}
}
So basically webpack returns __dirname to be /. So you basically have to tell webpack to resolve __dirname.
add:
node: {
__dirname: true
}
same thing with __filename as well.

Can't find index.html when bundling Node.js server with Webpack

I'm trying to setup webpack to bundle my backend code.
My webpack config looks like:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const outputDirectory = 'dist';
const client = {
mode: 'production',
entry: {
'app': [
'babel-polyfill',
'./client/index.js'
]
},
output: {
path: path.join(__dirname, outputDirectory),
publicPath: '/',
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.(js|jsx)$/, exclude: /node_modules/, loader: 'babel-loader'
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(gif|svg|jpg|png)$/,
loader: "file-loader"
}
]
},
plugins: [
new CleanWebpackPlugin([outputDirectory]),
new HtmlWebpackPlugin({
template: './index.html',
})
]
}
const server = {
mode: 'production',
target: 'node',
entry: {
'app': [
'./server/server.js'
]
},
externals: [nodeExternals()],
output: {
path: path.join(__dirname, '/server'),
filename: 'server.bundle.js'
}
}
module.exports = [client, server]
If I run the non-webpack server.js, everything works fine. However if I run the webpack bundled server.bundle.js, express throws:
Error: ENOENT: no such file or directory, stat '/dist/index.html'
Both server files are in the same directory. Has anyone run into this issue before?
I figured it out, it's not explicitly stated in webpack's documentation but you need to configure a "node" property when using express
Ex. add this to your config
node: {
// Need this when working with express, otherwise the build fails
__dirname: false, // if you don't put this is, __dirname
__filename: false, // and __filename return blank or /
},

Having trouble getting rollbar.js to build in a node/webpack-based project

We're hoping to use Rollbar.js in our node/webpack/babel/ES6/React-based project. It's not 100% clear what the right NPM package is to use, but it appears to be this one:
https://www.npmjs.com/package/rollbar
From there, the instructions are pretty straightforward: add a reference to package.json, install, and off you go. So here's the reference in package.json:
"rollbar": "0.6.2",
Running npm install appears to work just fine, but then when I run npm start, I get this error in the console:
ERROR in ./~/rollbar/lib/parser.js
Module not found: Error: Cannot resolve module 'fs' in [myProjectRoot]node_modules/rollbar/lib
# ./~/rollbar/lib/parser.js 7:9-22
ERROR in ./~/rollbar/package.json
Module parse failed: [myProjectRoot]node_modules/rollbar/package.json Unexpected token (2:9)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (2:9)
at Parser.pp.raise ([myProjectRoot]node_modules/webpack/node_modules/acorn/dist/acorn.js:923:13)
at Parser.pp.unexpected ([myProjectRoot]node_modules/webpack/node_modules/acorn/dist/acorn.js:1490:8)
at Parser.pp.semicolon ([myProjectRoot]node_modules/webpack/node_modules/acorn/dist/acorn.js:1469:73)
at Parser.pp.parseExpressionStatement ([myProjectRoot]node_modules/webpack/node_modules/acorn/dist/acorn.js:1994:8)
at Parser.pp.parseStatement ([myProjectRoot]node_modules/webpack/node_modules/acorn/dist/acorn.js:1772:188)
at Parser.pp.parseBlock ([myProjectRoot]node_modules/webpack/node_modules/acorn/dist/acorn.js:2009:21)
at Parser.pp.parseStatement ([myProjectRoot]node_modules/webpack/node_modules/acorn/dist/acorn.js:1753:19)
at Parser.pp.parseTopLevel ([myProjectRoot]node_modules/webpack/node_modules/acorn/dist/acorn.js:1666:21)
at Parser.parse ([myProjectRoot]node_modules/webpack/node_modules/acorn/dist/acorn.js:1632:17)
at Object.parse ([myProjectRoot]node_modules/webpack/node_modules/acorn/dist/acorn.js:885:44)
# ./~/rollbar/lib/notifier.js 14:18-44
I can't make any sense out of this. It appears to suggest that my webpack project cannot parse Rollbar's package.json file, but that doesn't seem possible, given that my webpack project has countless other NPM packages, each with their own package.json file.
Anybody run into this issue?
UPDATE:
In case it's relevant, here's our complete webpack.config.js file:
const path = require('path');
const webpack = require('webpack');
const glob = require('glob');
const modulesDirectories = glob.sync('src/**');
const assetsDirectories = glob.sync('assets/**');
Array.prototype.push.apply(
modulesDirectories,
assetsDirectories
);
modulesDirectories.push('assets');
modulesDirectories.push('/');
modulesDirectories.push('node_modules');
const modulesDirectoriesWithoutFiles = modulesDirectories.filter(directory => {
if (directory.slice(-4, -3) === '.' || directory.slice(-3, -2) === '.') {
return false;
}
return true;
});
module.exports = {
cache: true,
devtool: 'cheap-module-eval-source-map',
entry: [
'eventsource-polyfill',
'webpack-hot-middleware/client',
'./src/index.js'
],
module: {
loaders: [
{
test: /\.(js|jsx)$/,
loader: 'babel',
query: {
// https://github.com/babel/babel-loader#options
cacheDirectory: true
},
include: path.join(__dirname, 'src'),
exclude: /node_modules/
},
{ test: /\.css$/, loader: 'style-loader!css-loader' },
{ test: /\.woff|.ttf|.eot|.woff2$/, loader: `file-loader` },
{ test: /\.(png|jpe?g|gif|svg)$/, loader: `url-loader?limit=8192` },
]
},
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.DefinePlugin({
FIREBASE_CONFIG: JSON.stringify({
apiKey: [ourApiKey],
authDomain: [ourDomain],
databaseURL: [ourUrl],
storageBucket: [ourBucket],
})
})
],
resolve: {
extensions: ['', '.js', '.jsx'],
root: __dirname,
modulesDirectories: modulesDirectoriesWithoutFiles,
}
};
SECOND UPDATE:
Still can't get things to build, but I've got a little more information. If I remove the Rollbar import from my code, then the console errors go away. I've tried importing Rollbar in two ways, as follows:
import rollbar from "rollbar";
var Rollbar = require('rollbar');
Both attempts produce the same error. If I add node: {fs: "empty"} to my webpack.config.js file, then the 'fs' error disappears, but the "appropriate loader" error remains.
I was encountering the same issue. I fixed it by:
Installing fs using npm install --save fs. Alternatively, you can add node: {fs: "empty"} to your webpack config, as suggested in comments. Either of these takes care of the fs import in rollbar/lib/parser.js.
Installing a json loader, then adding this loader to your webpack config under modules -> loaders. This informs webpack that it should use the json loader when loading JSON files. Webpack should then be able to import package.json in rollbar/lib/notifier.js.
module: {
loaders: [
{
test: /\.json$/,
loader: "json"
},
...
],
...
}

How to compile .less files from an npm dependency using webpack?

I'm using the npm module elemental, which contains a /less folder with all the relevant styling for its react ui. I'm currently trying to do this with less-loader:
/tasks/config/webpack.js:
'use strict';
let path = require('path');
let ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = function(grunt) {
grunt.config.set('webpack', {
client: {
entry: {
app: `${process.cwd()}/src/app.jsx`,
},
output: {
filename: '[name].js',
chunkFilename: '[id].js',
path: `${process.cwd()}/dist`,
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components|dist)/,
loader: 'babel',
query: {
presets: ['react', 'es2015'],
},
},
{
test: /\.less$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!less-loader'),
},
],
},
plugins: [
new ExtractTextPlugin('[name].css'),
],
},
});
grunt.loadNpmTasks('grunt-webpack');
};
/src/app.jsx:
'use strict';
let path = require('path');
require(path.resolve(process.cwd(), 'node_modules/elemental/less/elemental.less'));
But this doesn't seem to work, as it generates a warning:
WARNING in ./src/app.jsx
Critical dependencies:
5:0-82 the request of a dependency is an expression
# ./src/app.jsx 5:0-82
WARNING in ./src ^\.\/.*$
Module not found: Error: a dependency to an entry point is not allowed
# ./src ^\.\/.*$
I'm interpreting this to mean that you can't use require()s that include files from inside node_modules.
Edit
Just to note, there are no .css files output anywhere, nor does the output /dist/app.js work properly.
Why not try just write require('elemental/less/elemental.less'); ?
In your error message: "5:0-82 the request of a dependency is an expression".

Resources