I want to build my graphql server app, when i build by webpack 4, i've got this error on a decorator of typeorm :
ERROR in ./src/models/user.ts 15:0
Module parse failed: Unexpected character '@' (15:0)
You may need an appropriate loader to handle this file type.
| import { JWT } from './jwt';
|
> @Entity()
| @Unique(['username'])
| @Unique(['email'])
@ ./src/server.ts 15:0-37 34:45-49
The webpack.config.js is like this :
var ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
var fs = require('fs');
var path = require('path');
var nodeExternals = require('webpack-node-externals');
module.exports = {
mode: 'production',
entry: './src/server.ts',
output: {
path: __dirname + '/dist',
filename: '[name].[chunkhash:8].js',
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
module: {
rules: [
{
test: '/\.tsx?$/',
exclude: '/node_modules/',
include: path.resolve(__dirname, 'src'),
use: {
loader: 'ts-loader',
options: {
transpileOnly: true
}
}
}
]
},
plugins: [
new ForkTsCheckerWebpackPlugin()
],
externals: [nodeExternals()],
};
The tsconfig.json is like this :
{
"exclude": [
"fixtures",
"tests"
],
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"outDir": "dist",
"rootDir": "src",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"typeRoots": [
"node_modules/@types"
],
"lib": ["es2016", "esnext.asynciterable"]
}
}
When i compile with tsc, i've not got any error but i've got this error when i launch app by node dist/server.js
:
(function (exports, require, module, __filename, __dirname) { import { Field, ID, Int, ObjectType } from 'type-graphql';
SyntaxError: Unexpected token {
Could you help me to resolve this bug ? Thanks for advance
It looks like ts-loader
isn't being used. I think that's because you've specified the test
as a string instead of a regular expression. Try removing the surrounding single quotes. See the example in the documentation.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments