我创建了一个如下所示的共享模块。我在某处读到进口订单很重要,但我现在找不到那个链接。在某些地方它工作正常,但在其他地方我收到错误。我想知道这些模块需要的顺序以避免任何错误。
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import 'hammerjs';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { MaterialModule } from '@angular/material';
import { FlexLayoutModule } from '@angular/flex-layout';
import { CoreModule } from './core/core.module';
// NOTE: The import order matters.
const modules = [
CommonModule,
CoreModule,
ReactiveFormsModule,
FormsModule,
HttpClientModule,
MaterialModule,
FlexLayoutModule,
];
@NgModule({
imports: modules,
exports: modules
})
export class DependenciesModule { }
Run Code Online (Sandbox Code Playgroud) 如何在“npm run build”中包含运行时依赖项?我应该这样做吗?
如果没有,在另一台机器上运行构建的做法是什么?
错误
找不到模块'@angular/material
app.module.ts
import { MaterialModule } from '@angular/material';
Run Code Online (Sandbox Code Playgroud)
链接:https : //material.angular.io/guide/getting-started
npm install --save @angular/material @angular/cdk
Run Code Online (Sandbox Code Playgroud)
我尝试过的解决方案
更新
它不起作用。
ng --version
@angular/cli: 1.2.1
node: 8.3.0
os: win32 x64
@angular/animation: 4.0.0-beta.8
@angular/animations: error
@angular/cdk: error
@angular/common: 4.3.2
@angular/compiler: 4.3.2
@angular/core: 4.3.2
@angular/forms: 4.3.2
@angular/http: 4.3.2
@angular/material: error
@angular/platform-browser: 4.3.2
@angular/platform-browser-dynamic: 4.3.2
@angular/router: 4.3.2
@angular/cli: 1.2.1
@angular/compiler-cli: 4.4.3
@angular/language-service: 4.3.2
Run Code Online (Sandbox Code Playgroud)
我已经做了工作演示https://github.com/afeef1915/Angular2-Symfony3-Demo
所有代码都运行良好。
安装材料时出错
D:\Angular2-Symfony3-Demo-master>npm install --save @angular/material @angular/cdk
npm WARN @angular/animation@4.0.0-beta.8 requires a peer of …Run Code Online (Sandbox Code Playgroud) 这可能是一个愚蠢的问题,但我真的想知道有没有办法npm install通过删除整个包安装详细信息的详细信息,在运行命令时只查看错误/成功日志。
是否有任何有用的可选参数可以与npm install命令一起传递,它只会给出最少的日志,而没有对每个依赖项安装的详细描述?
是否有一个 NPM CLI 命令可以用来获取我的包中安装的 NPM 模块的数量,不包括那些只是开发依赖项的模块?npm ls显示所有包,但没有说明有多少或哪些是开发依赖项,哪些不是。谢谢!
我正在尝试生成我的应用程序的文档(使用 TypeDoc)。我有相当困难的场景要做。所以在我的代码中是一些函数,它返回类型为 from 的对象node_modules/@types。我需要将此类型包含在我的文档中,因为我需要显示对此的引用@type并且我也需要显示它@type。所以我正在尝试这些方法:
在“src”语句中添加了此类型的路径,例如:'**/node_modules/@types/someType/index.d.ts'。我的 TypeDoc 配置:
typedoc: {
build: {
options: {
module: 'commonjs',
out: '../MyDocumentation/',
name: 'MyApp',
target: 'es5',
exclude: [
'**/folderA/*.d.ts',
'**/folderB/*.d.ts'
],
excludePrivate: true,
externalPattern: "**/*/{fileX,fileY,fileZ}.ts",
mode: 'file'
},
src: [
'folderA/*.ts',
'folderB/*.ts',
'**/node_modules/@types/someType/*.d.ts'
]
}
}
Run Code Online (Sandbox Code Playgroud)通过将 includeDeclarations 设置为 true。我的 TypeDoc 配置:
typedoc: {
build: {
options: {
module: 'commonjs',
out: '../MyDocumentation/',
name: 'MyApp',
target: 'es5',
exclude: [
'**/node_modules/**',
'**/folderA/*.d.ts',
'**/folderB/*.d.ts'
],
includeDeclarations: true,
excludePrivate: true,
externalPattern: …Run Code Online (Sandbox Code Playgroud)如何编写可以从命令行或通过 ES6 导入语句运行的 Node 脚本?
我正在使用--experimental-modules标志和.mjs扩展来将脚本作为 ES6 模块运行。
假设我有以下脚本sayHello.mjs:
export default function sayHello() {
console.log(`Hello!`);
}
Run Code Online (Sandbox Code Playgroud)
我希望能够通过以下两种方式使用此脚本:
通过命令行:
node --experimental-modules sayHello.mjs
Run Code Online (Sandbox Code Playgroud)通过另一个脚本中的 ES6 导入语句:
node --experimental-modules sayHello.mjs
Run Code Online (Sandbox Code Playgroud)我正在寻找类似于module.main用于 CommonJS 模块的解决方案(这不适用于 ES6 导入):
import sayHello from './sayHello.mjs';
sayHello();
Run Code Online (Sandbox Code Playgroud) 我以这种方式连接到 MQTT:
//mqtt.js
const mqtt = require('mqtt');
var options = {
//needed options
};
var client = mqtt.connect('mqtt://someURL', options);
client.on('connect', () => {
console.log('Connected to MQTT server');
});
Run Code Online (Sandbox Code Playgroud)
我想以这种方式导出客户端对象:
//mqtt.js
module.exports = client;
Run Code Online (Sandbox Code Playgroud)
这样我就可以将它导入其他文件并以这种方式使用它:
//anotherFile.js
const client = require('./mqtt');
client.publish(...)
Run Code Online (Sandbox Code Playgroud)
但是,我们都知道这是行不通的!我怎样才能做到这一点?
更新
我尝试了promise并得到了一个非常奇怪的行为。当我像下面的代码一样在同一个文件 (mqtt.js) 中使用 promise 时,一切正常:
//mqtt.js
const mqtt = require('mqtt');
var mqttPromise = new Promise(function (resolve, reject) {
var options = {
//needed options
};
var client = mqtt.connect('mqtt://someURL', options);
client.on('connect', () => { …Run Code Online (Sandbox Code Playgroud) 根据文档(https://nodejs.org/api/globals.html),require()函数是全局对象/函数之一。但是我很难在 Github 上找到它的源代码。它们是用 JS 还是 C++ 编写的?我在https://github.com/nodejs/node项目中寻找它们。
我正在使用react-html-table-to-excel,我想做的是更改导出按钮的样式。因此,我将文件定位在:node_module/react-html-table-to-excel/src/ReactHTMLTableToExcel.jsx并按照我想要的方式更改了它。
但是,当我保存文件并刷新浏览器时,更改并未反映在浏览器中。为了确保,我什至注释掉了整个文件并重新启动了服务器,但仍然没有对导出按钮进行任何更改。
任何帮助是极大的赞赏!
node-modules ×10
node.js ×6
javascript ×3
npm ×3
angular ×2
npm-install ×2
es6-modules ×1
export ×1
gruntjs ×1
mqtt ×1
reactjs ×1
require ×1
typedoc ×1
typescript ×1