Closed inradius closed 5 years ago
Unfortunately, some Node.js packages (especially native bindings, e.g. fsevents
in this case) cannot be easily bundled using Webpack. In order to get rid of errors, you have to adjust your webpack configuration (webpack.server.config.js
):
const webpack = require('webpack');
const WebpackConfigFactory = require('@nestjs/ng-universal')
.WebpackConfigFactory;
const nodeExternals = require('webpack-node-externals');
/**
* In fact, passing following configuration to the WebpackConfigFactory is not required
* default options object returned from this method has equivalent entries defined by default.
*
* Example: WebpackConfigFactory.create(webpack);
*/
const webpackOptions = WebpackConfigFactory.create(webpack, {
// This is our Nest server for Dynamic universal
server: './server/main.ts',
// This is an example of Static prerendering (generative)
prerender: './prerender.ts',
});
webpackOptions.resolve.extensions.push('.mjs', '.graphql', '.gql');
webpackOptions.module.rules.push({
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
});
const whitelistedPackages = /^(?!(livereload|concurrently|fsevents)).*/;
webpackOptions.externals[1] = nodeExternals({
whitelist: whitelistedPackages,
});
webpackOptions.plugins.push(
new webpack.IgnorePlugin({
checkResource(resource) {
const lazyImports = [
'@nestjs/microservices',
'cache-manager',
'class-validator',
'class-transformer',
'apollo-server-fastify',
'bufferutil',
'utf-8-validate',
];
if (!lazyImports.includes(resource)) {
return false;
}
try {
require.resolve(resource);
} catch (err) {
return true;
}
return false;
},
}),
);
module.exports = webpackOptions;
Then, it will work fine
I'm submitting a...
Current behavior
When implementing the @nestjs/graphql package into a project using @nestjs/ng-universal following the provided installation instructions, the
webpack
command results in errors when building.Seems to be related to the WebpackConfigFactory and it not being configured to build for this scenario (.mjs file extensions, etc.)
Expected behavior
A basic @kamilmysliwiec/universal-nest starter application can be extended to use @nestjs/graphql without failing to compile
Minimal reproduction of the problem with instructions
npm run build:ssr && npm run serve:ssr
commandYou should see this fail when getting to the
webpack --config webpack.server.config.js --progress --colors
portion of the build.What is the motivation / use case for changing the behavior?
Integrate @Nestjs/GraphQL with an Angular Universal application running on Nest.js Universal module.
Environment