在某些情况下,我很难使用 JEST 来运行我得到的测试
测试套件运行失败
...node_modules\p-retry\index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import retry from 'retry';
^^^^^^
SyntaxError: Cannot use import statement outside a module
> 1 | import pRetry from 'p-retry';
| ^
2 |
3 | export function Retry(tries: number) {
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1728:14)
at Object.<anonymous> (src/common/Retry.ts:1:1)
Run Code Online (Sandbox Code Playgroud)
同时,我的 webpack 构建与 typescript 和 babel 配合得很好。我尝试了很多东西(见下文以使其工作,但到目前为止没有成功 - 并且还没有真正能够理解发生了什么。从我的角度来看 - 尽管转译的东西到目前为止对我来说是一个黑色区域我尝试让 Jest 使用 ESModules 并提供代码,并尝试提供 commonJS 模块代码。
因此,我正在寻找其他选择和方法来进一步调查。特别是一件事让我感到奇怪:错误中的 Retry.ts 文件是我的文件之一,它导入 pRetry (以 ESModule 风格编写的 node_module ),它在其代码中从“retry”(另一个节点模块)导入重试以 commonJS 风格编写)从错误的第一行开始。
所以在我看来,pRetry 并不是从它的 ESModule 代码转换而来(pRetry 的源代码以 import retry from 'retry'; 开始),而只是包装在一些 …
我将 Nest.js 与打字稿一起使用并想添加
import { DRACOLoader, GLTFLoader, TextureLoader } from 'node-three-gltf';
Run Code Online (Sandbox Code Playgroud)
在我的一个模块中。但这会导致以下错误
c:\m3\dist\src\gltftest\gltftest.controller.js:23
const node_three_gltf_1 = require("node-three-gltf");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module c:\m3\node_modules\node-three-gltf\build\index.js from c:\m3\dist\src\gltftest\gltftest.controller.js not supported.Instead change the require of index.js in c:\m3\dist\src\gltftest\gltftest.controller.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (c:\m3\dist\src\gltftest\gltftest.controller.js:23:27)
at Object.<anonymous> (c:\m3\dist\src\gltftest\gltftest.module.js:12:30)
Run Code Online (Sandbox Code Playgroud)
我使用的 node-三-gltf@1.0.3 只是一个 esm 模块。导致我在打字稿模块/控制器中使用 ESM 导入语法来导入 ESM 模块 node- Three-gltf 并收到此错误(至少对我来说 - 对这个问题相当陌生)奇怪的情况。
似乎是因为我的项目的 Nest.js 构建将我的 ES 语法转换为 CJS 语法,从而用 require 替换了我的导入,但没有转换 node-3-gltf 模块,然后抱怨。
我的 tsconfig …
我正在尝试在 Three.js 中加载字体,到目前为止这非常困难。希望某人能在这件事上提供帮助。
我尝试使用 javascript 字体,就像《掌握三.js》一书中所建议的那样。书中的版本有效。我必须升级到 Three.js 的最新版本,但由于另一个原因,本书中的字体不适用于最新的 Three.js 版本。所以我尝试通过https://gero3.github.io/facetype.js/将 Three.js 的 json 字体转换为 js-fonts ,但这不起作用,因为当我按下转换按钮时,网站不会执行任何操作。
然后我尝试使用 FontLoader 来了解最新 Three.js 版本中的一些示例。由于 FontLoader 不返回任何内容,因此我很难获取字体。因此,尝试将字体分配给传递给 FontLoader 的函数中的全局变量 myfont。然而,当我执行 loader.load(...) 时,该函数不会被调用,但在我的代码中,只有当我放在此处的代码片段的最后一行被执行时,该函数才会被调用。即我事先在代码中发现错误。为什么代码只在那时执行而不是在我加载字体时执行,是否有充分的理由?
干杯汤姆
var loader = new THREE.FontLoader();
loader.load( 'three.js-master/examples/fonts/helvetiker_regular.typeface.json', function ( font ) {
init( font );
} );
var myfont;
function init( font ) {
myfont = font;
console.log("inner value "+myfont);
}
console.log("2nd time" +myfont);
var params = {
material: 0,
extrudeMaterial: 1,
bevelEnabled: false,
bevelThickness: 8,
bevelSize: 4,
font: …
Run Code Online (Sandbox Code Playgroud) 在我的网站上,我不想捆绑而是直接使用 ES6 模块(适用于观众)
我尝试导入fabric.js
import {fabric} from "../node_modules/fabric/dist/fabric.js";
就像我捆绑时所做的一样(对于捆绑来说,它工作正常)。
但是当我启动网站时
“未捕获的语法错误:请求的模块 '../node_modules/fabric/dist/fabric.js' 不提供名为 'fabric' 的导出”
如果我将上述更改为
import * as FAB from "../node_modules/fabric/dist/fabric.js";
我得到
未捕获的类型错误:无法读取 fabric.js:3224 处未定义的属性“fabric”
关于如何将结构直接用作 ES6 模块而不捆绑的任何想法?不用说,我在使用 Chrome 76.0.3809.132 时导入的其他模块没有这个问题
升级到fabric 3.4 无济于事。让我在这里粘贴我的整个代码: html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="module" src="./start.js"></script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
以及我从中删除所有其他内容的 JS
import fabric from '../node_modules/fabric/dist/fabric.min.js';
还是一样的错误
未捕获的语法错误:请求的模块“../node_modules/fabric/dist/fabric.min.js”不提供名为“default”的导出
我对 BufferGeometryUtils.mergeVertices 方法有一个奇怪的问题
我从 jsfiddle 中取出了一个简单的立方体并执行了 mergeVertices,看起来 mergeVertices 并没有像它应该的那样合并所有相同的顶点。参见https://jsfiddle.net/tomfree/vpdwmycn/
例如,mergeVertices 返回的 indexGeometry 中给出的顶点是
Index 0 = (-1, -1, 1, )
index 1 = (1, -1, 1,)
index 2= (-1, 1, 1, )
index 3= (1, 1, 1,)
index 4= (1, -1, 1)
Run Code Online (Sandbox Code Playgroud)
即位置 1 和 4 处的顶点似乎相同,但根据我的理解,在 mergeVertices 之后不应相同。我很确定我错过了某事。有人能指出我正确的方向吗?
干杯汤姆
ps:也在Three.js 论坛中发布为https://discourse.thirdjs.org/t/buffergeometryutils-mergevertices-seems-not-to-merge-all-identical-vertices/33890
我正在使用maven(即Eclipse的maven插件)进行依赖项管理,并且通常可以正常工作。例如,jasypt可以解决强文本问题,并且我可以毫无问题地使用它。但是,当我尝试使用Log4J时,即使遵循了http://logging.apache.org/log4j/2.x/maven- artifacts.html。
那里说我需要在我的pom.xml中包含以下代码段
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.6.2</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
但是,正好包含在我的pom.xml中,如下文完整的pom.xml所示。这对任何人有意义吗?我也尝试用以下替换两个依赖项,但是没有成功
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId>
<version>2.6.2</version>
<type>pom</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)
干杯汤姆
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>PCenter</groupId>
<artifactId>PCenter</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>PCenter</name>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>ejbModule</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.paypal.sdk</groupId>
<artifactId>rest-api-sdk</artifactId>
<version>1.9.2</version>
</dependency>
<dependency> …
Run Code Online (Sandbox Code Playgroud) 我想应用 TerserPlugin 来优化我的一些代码,并从 Terser 处理中排除一些第三方库(例如 vue),但是无论我尝试测试什么,包含和排除都不起作用。我的代码是用 Typescript(只有 *.ts 文件没有 .vue 文件)和大多数带有 js 的 3rd 方库编写的,以防以后很重要。
我尝试使用 followig 正则表达式和字符串进行测试,包括和排除 TerserPlugin 就像这样,给定的结果:
1.) 没有指定测试子句,没有排除,没有包括:应用了 Terser,例如在我的东西和 3rd 方库中替换了方法的局部变量。这实际上很奇怪,因为test
默认设置是/\.m?js(\?.*)?$/
根据https://github.com/webpack-contrib/terser-webpack-plugin这对任何 *.ts 文件都是不正确的。因此我的 Typescript 文件不应该由 Terser 处理,而是
2.) test: /\.ts$/i
- 我的文件或第三方库中没有更简洁的转换
3.) include: /\.ts$/i
- 我的文件或第三方库中没有更简洁的转换
4.) include: /entities/i
- 我的文件中没有更简洁的转换(一对在目录名称实体中)或第三方库
5.) exclude: /vue/i
- 应用了 Terser,例如在我的东西和 3rd 方库中替换了方法的局部变量
6.) exclude: "C:\Repositories\m2\node_modules\vue\dist\vue.esm.js"
- 应用了 Terser,例如在我的东西和 3rd 方库中替换了方法的局部变量
7.) exclude: "C:/Repositories/m2/node_modules/vue/dist/vue.esm.js"
- 应用了 Terser,例如在我的东西和 3rd 方库中替换了方法的局部变量
8.) exclude: path.join(__dirname, 'node_modules/vue/dist/vue.esm.js') …
three.js ×2
babel-jest ×1
babeljs ×1
fabricjs ×1
java ×1
javascript ×1
jestjs ×1
log4j ×1
maven ×1
maven-plugin ×1
nestjs ×1
typescript ×1
webpack ×1