Typescript没有为'/path/to/file.ts';
我有一个用typescript写的库。我可以使用Typescript没有为'/path/to/file.ts';,typescript,webpack,ts-loader,Typescript,Webpack,Ts Loader,我有一个用typescript写的库。我可以使用tsc和下面的配置来传输它,没有任何问题 { "compilerOptions": { "target": "es6", "module": "commonjs", "lib": [ "es6", "es5", "dom", "es2017" ], "declaration": true, "declarationMap": true, "s
tsc
和下面的配置来传输它,没有任何问题
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"es6",
"es5",
"dom",
"es2017"
],
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./dist",
"strict": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"listEmittedFiles": true
},
"exclude": [
"./dist",
"./test",
"./bin"
],
"include": [
"./lib"
]
}
但是,当另一个项目尝试从链接的npm包使用此库时,它无法使用webpack
和ts loader
进行传输和绑定。对于库的所有文件,网页包获取错误:
错误:Typescript没有为/library/path/to/file.ts发出任何输出
注意:webpack试图从链接的目的地加载它,而不是从node\u modules
加载,因为它与npm链接
项目使用库的网页包配置如下
module.exports = (entry, dist) => Object.assign({
entry,
mode: "production",
output: {
filename: "index.js",
path: dist,
},
resolve: {
extensions: [".js", ".ts"]
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
stats: 'verbose'
});
项目的tsconfig.json使用库
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"es6",
"es5",
"dom",
"es2017"
],
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./dist",
"strict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"exclude": [
"./dist"
],
"include": [
"./index.ts"
]
}
以及未发出输出的库文件示例:
import {Ctor, Injector} from "./injector";
import {ERROR_CODES, PuzzleError} from "./errors";
import {Route} from "./server";
export interface ApiEvents {}
export interface ApiConfig {
route: Route;
subApis?: Array<Ctor<Api>>;
}
interface ApiBase {
}
export function PuzzleApi<T>(config: ApiConfig) {
return Injector.decorate((constructor: () => void) => {
console.log(`Registering Api: ${constructor.name}`);
}, config);
}
export class Api implements ApiBase {
config: ApiConfig;
constructor() {
const config = (this.constructor as any).config as ApiConfig;
if (!config) {
throw new PuzzleError(ERROR_CODES.CLASS_IS_NOT_DECORATED, this.constructor.name);
} else {
this.config = config;
}
}
}
从“/Injector”导入{Ctor,Injector};
从“/errors”导入{ERROR\u代码,拼图错误};
从“/server”导入{Route};
导出接口ApiEvents{}
导出接口ApiConfig{
路线:路线;
subApis?:数组;
}
接口ApiBase{
}
导出函数API(配置:ApiConfig){
返回喷油器。装饰((构造函数:()=>void)=>{
log(`registingapi:${constructor.name}`);
},config);
}
导出类Api实现ApiBase{
配置:ApiConfig;
构造函数(){
const config=(this.constructor作为any.config作为ApiConfig;
如果(!config){
抛出新的拼图错误(错误\u代码.CLASS\u未\u修饰,this.constructor.name);
}否则{
this.config=config;
}
}
}
我找不到它不为那个项目输出的任何原因。我可以毫无问题地传送图书馆。有人能帮我一下吗?如果应用程序试图从库(即从
lib
子目录)导入TypeScript源文件,我可以重现此错误。尝试从dist
子目录导入生成的JavaScript文件。如果您确实希望将库作为应用程序的一部分重新编译,则可能需要将其添加到应用程序的tsconfig.json
中的“include”
列表中。“如果您确实希望将库作为应用程序的一部分重新编译…”这在我的情况下不起作用。