Jest cannot find module from node_modules
I'm creating typescript base npm module, but i stuck with jest tests. I'm trying to include jsonld module from https://github.com/types/jsonld and everything seems work fine, but when i run command yarn test i have error message Cannot find module 'jsonld' from 'DidDocument.ts'
package.json
{
"name": "defined-id",
"version": "1.0.0",
"description": "Defined ID",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"test": "jest --config jestconfig.json",
"build": "tsc",
"format": "prettier --write "src/**/*.ts" "src/**/*.js"",
"lint": "tslint -p tsconfig.json",
"prepare": "yarn run build",
"prepublishOnly": "yarn test && yarn run lint",
"preversion": "yarn run lint",
"version": "yarn run format && git add -A src",
"postversion": "git push && git push --tags"
},
"repository": {
"type": "git",
"url": "git+https://github.com/VSaulis/defined-id.git"
},
"keywords": [
"DID",
"DID document"
],
"author": "Vytautas Saulis",
"license": "ISC",
"bugs": {
"url": "https://github.com/VSaulis/defined-id/issues"
},
"homepage": "https://github.com/VSaulis/defined-id#readme",
"devDependencies": {
"@types/jest": "^23.3.9",
"jest": "^23.6.0",
"prettier": "^1.15.2",
"ts-jest": "^23.10.5",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.16.0",
"typescript": "^3.1.6"
},
"dependencies": {
"@types/jsonld": "github:types/jsonld",
"@types/uuid": "^3.4.4"
}
}
jestconfig.json
{
"transform": {
"^.+\.(t|j)sx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\.|/)(test|spec))\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
"moduleDirectories": ["node_modules", "src"]
}
DidDocument.ts
import * as jsonld from 'jsonld';
import { Did } from './Did';
import { PublicKey } from './PublicKey';
export class DidDocument {
private context: string = ["https://w3id.org/did/v1", "https://w3id.org/security/v1"];
private did: Did;
private publicKeys: PublicKey;
constructor(did: Did, publicKeys: PublicKey) {
this.did = did;
this.publicKeys = publicKeys;
}
public format(): void {
const doc = {
"http://schema.org/id": this.did.format(),
"publicKey": this.publicKeys.map((publicKey: PublicKey) => JSON.stringify(publicKey.format()))
};
return jsonld.compact(doc, JSON.stringify(this.context), () => { return; });
}
}
I have prediction that jsonld module is not in root directory but in js/ directory. But when i changed import to jsonld/js issues still the same.
typescript types jestjs json-ld
add a comment |
I'm creating typescript base npm module, but i stuck with jest tests. I'm trying to include jsonld module from https://github.com/types/jsonld and everything seems work fine, but when i run command yarn test i have error message Cannot find module 'jsonld' from 'DidDocument.ts'
package.json
{
"name": "defined-id",
"version": "1.0.0",
"description": "Defined ID",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"test": "jest --config jestconfig.json",
"build": "tsc",
"format": "prettier --write "src/**/*.ts" "src/**/*.js"",
"lint": "tslint -p tsconfig.json",
"prepare": "yarn run build",
"prepublishOnly": "yarn test && yarn run lint",
"preversion": "yarn run lint",
"version": "yarn run format && git add -A src",
"postversion": "git push && git push --tags"
},
"repository": {
"type": "git",
"url": "git+https://github.com/VSaulis/defined-id.git"
},
"keywords": [
"DID",
"DID document"
],
"author": "Vytautas Saulis",
"license": "ISC",
"bugs": {
"url": "https://github.com/VSaulis/defined-id/issues"
},
"homepage": "https://github.com/VSaulis/defined-id#readme",
"devDependencies": {
"@types/jest": "^23.3.9",
"jest": "^23.6.0",
"prettier": "^1.15.2",
"ts-jest": "^23.10.5",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.16.0",
"typescript": "^3.1.6"
},
"dependencies": {
"@types/jsonld": "github:types/jsonld",
"@types/uuid": "^3.4.4"
}
}
jestconfig.json
{
"transform": {
"^.+\.(t|j)sx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\.|/)(test|spec))\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
"moduleDirectories": ["node_modules", "src"]
}
DidDocument.ts
import * as jsonld from 'jsonld';
import { Did } from './Did';
import { PublicKey } from './PublicKey';
export class DidDocument {
private context: string = ["https://w3id.org/did/v1", "https://w3id.org/security/v1"];
private did: Did;
private publicKeys: PublicKey;
constructor(did: Did, publicKeys: PublicKey) {
this.did = did;
this.publicKeys = publicKeys;
}
public format(): void {
const doc = {
"http://schema.org/id": this.did.format(),
"publicKey": this.publicKeys.map((publicKey: PublicKey) => JSON.stringify(publicKey.format()))
};
return jsonld.compact(doc, JSON.stringify(this.context), () => { return; });
}
}
I have prediction that jsonld module is not in root directory but in js/ directory. But when i changed import to jsonld/js issues still the same.
typescript types jestjs json-ld
add a comment |
I'm creating typescript base npm module, but i stuck with jest tests. I'm trying to include jsonld module from https://github.com/types/jsonld and everything seems work fine, but when i run command yarn test i have error message Cannot find module 'jsonld' from 'DidDocument.ts'
package.json
{
"name": "defined-id",
"version": "1.0.0",
"description": "Defined ID",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"test": "jest --config jestconfig.json",
"build": "tsc",
"format": "prettier --write "src/**/*.ts" "src/**/*.js"",
"lint": "tslint -p tsconfig.json",
"prepare": "yarn run build",
"prepublishOnly": "yarn test && yarn run lint",
"preversion": "yarn run lint",
"version": "yarn run format && git add -A src",
"postversion": "git push && git push --tags"
},
"repository": {
"type": "git",
"url": "git+https://github.com/VSaulis/defined-id.git"
},
"keywords": [
"DID",
"DID document"
],
"author": "Vytautas Saulis",
"license": "ISC",
"bugs": {
"url": "https://github.com/VSaulis/defined-id/issues"
},
"homepage": "https://github.com/VSaulis/defined-id#readme",
"devDependencies": {
"@types/jest": "^23.3.9",
"jest": "^23.6.0",
"prettier": "^1.15.2",
"ts-jest": "^23.10.5",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.16.0",
"typescript": "^3.1.6"
},
"dependencies": {
"@types/jsonld": "github:types/jsonld",
"@types/uuid": "^3.4.4"
}
}
jestconfig.json
{
"transform": {
"^.+\.(t|j)sx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\.|/)(test|spec))\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
"moduleDirectories": ["node_modules", "src"]
}
DidDocument.ts
import * as jsonld from 'jsonld';
import { Did } from './Did';
import { PublicKey } from './PublicKey';
export class DidDocument {
private context: string = ["https://w3id.org/did/v1", "https://w3id.org/security/v1"];
private did: Did;
private publicKeys: PublicKey;
constructor(did: Did, publicKeys: PublicKey) {
this.did = did;
this.publicKeys = publicKeys;
}
public format(): void {
const doc = {
"http://schema.org/id": this.did.format(),
"publicKey": this.publicKeys.map((publicKey: PublicKey) => JSON.stringify(publicKey.format()))
};
return jsonld.compact(doc, JSON.stringify(this.context), () => { return; });
}
}
I have prediction that jsonld module is not in root directory but in js/ directory. But when i changed import to jsonld/js issues still the same.
typescript types jestjs json-ld
I'm creating typescript base npm module, but i stuck with jest tests. I'm trying to include jsonld module from https://github.com/types/jsonld and everything seems work fine, but when i run command yarn test i have error message Cannot find module 'jsonld' from 'DidDocument.ts'
package.json
{
"name": "defined-id",
"version": "1.0.0",
"description": "Defined ID",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"test": "jest --config jestconfig.json",
"build": "tsc",
"format": "prettier --write "src/**/*.ts" "src/**/*.js"",
"lint": "tslint -p tsconfig.json",
"prepare": "yarn run build",
"prepublishOnly": "yarn test && yarn run lint",
"preversion": "yarn run lint",
"version": "yarn run format && git add -A src",
"postversion": "git push && git push --tags"
},
"repository": {
"type": "git",
"url": "git+https://github.com/VSaulis/defined-id.git"
},
"keywords": [
"DID",
"DID document"
],
"author": "Vytautas Saulis",
"license": "ISC",
"bugs": {
"url": "https://github.com/VSaulis/defined-id/issues"
},
"homepage": "https://github.com/VSaulis/defined-id#readme",
"devDependencies": {
"@types/jest": "^23.3.9",
"jest": "^23.6.0",
"prettier": "^1.15.2",
"ts-jest": "^23.10.5",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.16.0",
"typescript": "^3.1.6"
},
"dependencies": {
"@types/jsonld": "github:types/jsonld",
"@types/uuid": "^3.4.4"
}
}
jestconfig.json
{
"transform": {
"^.+\.(t|j)sx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\.|/)(test|spec))\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
"moduleDirectories": ["node_modules", "src"]
}
DidDocument.ts
import * as jsonld from 'jsonld';
import { Did } from './Did';
import { PublicKey } from './PublicKey';
export class DidDocument {
private context: string = ["https://w3id.org/did/v1", "https://w3id.org/security/v1"];
private did: Did;
private publicKeys: PublicKey;
constructor(did: Did, publicKeys: PublicKey) {
this.did = did;
this.publicKeys = publicKeys;
}
public format(): void {
const doc = {
"http://schema.org/id": this.did.format(),
"publicKey": this.publicKeys.map((publicKey: PublicKey) => JSON.stringify(publicKey.format()))
};
return jsonld.compact(doc, JSON.stringify(this.context), () => { return; });
}
}
I have prediction that jsonld module is not in root directory but in js/ directory. But when i changed import to jsonld/js issues still the same.
typescript types jestjs json-ld
typescript types jestjs json-ld
edited Feb 13 at 13:37
Kais
1,03021238
1,03021238
asked Nov 25 '18 at 11:09
Vytautas SaulisVytautas Saulis
113
113
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466859%2fjest-cannot-find-module-from-node-modules%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466859%2fjest-cannot-find-module-from-node-modules%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown