I was building my MEAN project using AoT and I am getting this error, I've tried changing many loaders configurations. But nothing seems to work
[at-loader] Checking finished with 40 errors
Error in bail mode: [at-loader] ./node_modules/#angular/common/src/directives/ng_class.d.ts:48:34
TS2304: Cannot find name 'Set'.
My ts.config is
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "./public/js/app"
},
"typeRoots": [
"node_modules/#types"
],
"lib": [
"es5",
"dom"
],
"types": [
"hammerjs",
"node"
],
"angularCompilerOptions": {
"skipMetadataEmit": true
}
}
My common webpack.config is
var webpack = require('webpack');
module.exports = {
entry: {
'app': './assets/app/main.ts'
},
resolve: {
extensions: ['.js', '.ts']
},
module: {
rules: [
{
test: /\.html$/,
use: [{ loader: 'html-loader' }]
},
{
test: /\.css$/,
use: [{ loader: 'raw-loader' }]
}
],
exprContextCritical: false
}
};
aot webpack.config is
var path = require('path');
var webpack = require('webpack');
var webpackMerge = require('webpack-merge');
var commonConfig = require('./webpack.config.common.js');
module.exports = webpackMerge.smart(commonConfig, {
entry: {
'app': './assets/app/main.aot.ts'
},
output: {
path: path.resolve(__dirname + '/public/js/app'),
filename: 'bundle.js',
publicPath: '/js/app/',
chunkFilename: '[id].[hash].chunk.js'
},
module: {
rules: [
{
test: /\.ts$/,
use: [
'awesome-typescript-loader',
'angular2-template-loader',
'angular-router-loader?aot=true'
]
}
]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: false
})
]
});
Related
{
"extends": "../../tsconfig.json",
"include": [
"**/*.ts"
],
"exclude": [
"node_modules",
"build"
],
"compilerOptions": {
"baseUrl": ".",
"rootDir": ".",
"outDir": "build/",
"plugins": [
{
"name": "#rollup/plugin-typescript"
},
{
"name": "#rollup/plugin-json"
}
]
}
}
bumps into the following build error:
[!] TypeError: Module "file:///usr/src/Node.JSRestAPI/src/core/tsconfig.json" needs an import assertion of type "json"
TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "file:///usr/src/Node.JSRestAPI/src/core/tsconfig.json" needs an import assertion of type "json"
at new NodeError (node:internal/errors:393:5)
at validateAssertions (node:internal/modules/esm/assert:82:15)
at defaultLoad (node:internal/modules/esm/load:84:3)
at nextLoad (node:internal/modules/esm/loader:164:28)
at ESMLoader.load (node:internal/modules/esm/loader:603:26)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:459:22)
at new ModuleJob (node:internal/modules/esm/module_job:63:26)
at #createModuleJob (node:internal/modules/esm/loader:478:17)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:436:34)
at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:78:21)
I have set "resolveJsonModule": true, in top-level tsconfig.json
I need to execute seed file and when I execute the file this error appears. How can I solve it?
ERROR: Cannot use import statement outside a module
This is my tsconfig.js:
{
"compilerOptions": {
"module": "commonjs",
"target": "es2019",
"lib": [
"dom",
"es2019"
],
// "baseUrl": "./src",
"moduleResolution": "node",
"outDir": "dist",
"sourceMap": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"typeRoots": [
"./types",
"./node_modules/#types"
],
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
".vscode"
]
}
And this is my seeds:
'use strict';
import { Player } from "../../app/models/player";
module.exports = {
up: async (queryInterface, Sequelize) => {
return Player.bulkCreate(
[
{ name: "Inbal", email: "inbal#test.co.il",phone: "1111" },
{ name: "Tal", email: "tal#test.co.il",phone: "2222" },
{ name: "Sivan", email: "sivan#test.co.il" ,phone: "3333"}
],
{ hooks: true, individualHooks: true, validate: true }
);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete("players", null, {});
}
};
When I run npx sequelize-cli-ts db:seed:all the error appears.
Either use require instead of import in your seed file or you could also try to set
"type": "module"
in your package.json
I'm trying to use absolute path import form my custom modules and VSCode has no prob recognising them. The problem is that when I run firebase deploy which runs first eslint I get errors.
3:24 error Unable to resolve path to module '#src/stripe/lib/secret-key' import/no-unresolved
I have tried to set this
"import/resolver": {
"typescript": {}
}
in the eslintrc.js but I just get more and more errors. I have also tried to install some plugins but no luck.
Here is the line which throws the error.
import { stripe } from '#src/stripe/lib/secret-key'
tsconfig
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017",
"allowSyntheticDefaultImports": true,
"baseUrl": "./",
"paths": {
"#src/*": [
"./src/*"
]
}
},
"compileOnSave": true,
"include": [
"src"
]
}
eslintrc.js
module.exports = {
env: {
browser: true,
es6: true,
node: true,
},
extends: [
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
],
parser: "#typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
sourceType: "module",
},
plugins: [
"#typescript-eslint",
"import",
],
rules: {
"#typescript-eslint/adjacent-overload-signatures": "error",
"#typescript-eslint/no-empty-function": "error",
"#typescript-eslint/no-empty-interface": "warn",
"#typescript-eslint/no-floating-promises": "error",
"#typescript-eslint/no-namespace": "error",
"#typescript-eslint/no-unnecessary-type-assertion": "error",
"#typescript-eslint/prefer-for-of": "warn",
"#typescript-eslint/triple-slash-reference": "error",
"#typescript-eslint/unified-signatures": "warn",
"constructor-super": "error",
eqeqeq: ["warn", "always"],
"import/no-deprecated": "warn",
"import/no-extraneous-dependencies": "error",
"import/no-unassigned-import": "warn",
"no-cond-assign": "error",
"no-duplicate-case": "error",
"no-duplicate-imports": "error",
"no-empty": [
"error",
{
allowEmptyCatch: true,
},
],
"no-invalid-this": "error",
"no-new-wrappers": "error",
"no-param-reassign": "error",
"no-redeclare": "error",
"no-sequences": "error",
"no-shadow": [
"error",
{
hoist: "all",
},
],
"no-throw-literal": "error",
"no-unsafe-finally": "error",
"no-unused-labels": "error",
"no-var": "warn",
"no-void": "error",
"prefer-const": "warn",
},
settings: {
jsdoc: {
tagNamePreference: {
returns: "return",
},
},
},
};
Any idea how to make this work?
I have two projects:
App
A library (to share code)
On my app, I have one test using directly the source of my npm package library
import { mockAddress } from '#xxx/library/src/entities/address';
Issue
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config
option.
What I tried
I tried to add the folder of my library to transformIgnorePatterns
transformIgnorePatterns: [
'<roodDir>/node_modules/(?!vee-validate/dist/rules)',
'<roodDir>/node_modules/(?!#xxx/library/src)',
],
I tried to add transform
'\\.(ts|js)x?$': 'ts-jest'
EDIT 1
transform: {
'vee-validate/dist/rules': 'babel-jest',
'\\.(ts|tsx)?$': 'ts-jest',
},
transformIgnorePatterns: [
'node_modules/(?!vee-validate/dist/rules|#xxx/lib/)',
],
jest.config
module.exports = {
globals: {
'ts-jest': {
isolatedModules: true,
},
},
verbose: true,
preset: '#vue/cli-plugin-unit-jest/presets/typescript-and-babel',
collectCoverage: false,
collectCoverageFrom: [
'**/entities/**/*.ts',
'**/services/**/*.ts',
'**/store/**/*.ts',
'**/ui/components/**/*.{js,vue}',
'**/ui/views/**/**.{js,vue}',
'!src/main.ts', // No need to cover bootstrap file
'!**/store.ts',
'!**/*.mock.ts',
'!**/*.types.ts',
'!**/index.ts',
],
transform: {
'vee-validate/dist/rules': 'babel-jest',
'^.+\\.tsx?$': 'ts-jest',
},
transformIgnorePatterns: [
'<roodDir>/node_modules/(?!vee-validate/dist/rules)',
],
moduleNameMapper: {
'^#/(.*)$': '<rootDir>/src/$1',
},
testMatch: [
'**/*.(spec|test).(js|jsx|ts|tsx)',
],
roots: [
'<rootDir>/src',
],
testEnvironmentOptions: {
// Allow test environment to fire onload event
// See https://github.com/jsdom/jsdom/issues/1816#issuecomment-355188615
resources: 'usable',
},
reporters: [
'default',
[
'jest-trx-results-processor',
{
outputFile: './coverage/test-results.trx',
defaultUserName: 'user name to use if automatic detection fails',
},
],
],
};
tsconfig.json
{
"compilerOptions": {
"strictNullChecks": false,
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"types": [
"webpack-env",
"jest",
"vuetify",
"vue-meta"
],
"paths": {
"#/*": [
"src/*"
]
},
"lib": [
"es6",
"es2017",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx",
],
"exclude": [
"node_modules"
]
}
I have a CLI node app that I am trying to debug with VSCode. It works pretty well, however when hitting a breakpoint, VSCode opens a new code view from the source map file instead of the actual TS file located in my "src" folder. This is kind of annoying. When I run some JS code in a browser using VSCode as a debugger, VSCode opens the actual TS file as expected. How do I get this behavior also with node?
launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Node",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/bin/js/index.js",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}/bin/js",
"args": [
"authorize"
]
}
]
}
tsconfig.json:
{
"compilerOptions": {
"baseUrl": "./src",
"moduleResolution": "node",
"module": "ES2020",
"target": "ES2018",
"allowSyntheticDefaultImports": true,
"jsx": "react",
"strict": true,
"strictPropertyInitialization": true,
"noEmitOnError": true,
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"outDir": "./bin",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
webpack.config.json:
const path = require("path");
const webpack = require("webpack");
const { merge } = require('webpack-merge');
const commonConfig = {
target: 'node',
entry: "./src/Startup.ts",
module: {
rules: [
{
test: /\.tsx?$/,
use: [{
loader: "ts-loader"
}]
}
]
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"],
modules: ["./src", "node_modules"]
},
output: {
path: path.resolve(__dirname, "./bin/js/"),
filename: "index.js",
},
plugins: [
new webpack.DefinePlugin({ "global.GENTLY": false })
],
externals: {
'cliui': 'commonjs2 cliui',
'y18n': 'commonjs2 y18n',
'yargs-parser': 'commonjs2 yargs-parser',
}
}
const developmentConfig = {
mode: 'development',
devtool: 'source-map',
stats: {
warnings: false
}
}
const productionConfig = {
mode: 'production'
}
module.exports = (env, argv) => {
switch(argv.mode) {
case 'development':
return merge(commonConfig, developmentConfig);
case 'production':
return merge(commonConfig, productionConfig);
default:
throw new Error(`Configuration '${argv.mode}' does not exists.`);
}
}
The TS file paths generated by Webpack in the source map files are using the webpack protocol that VSCode did not understand. I solved it by adding this parameter in my webpack.config.js so the source map contains absolute paths to the TypeScript files instead:
const commonConfig = {
output: {
devtoolModuleFilenameTemplate: "[absolute-resource-path]",
},
}