Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vanilla node fails to import #69

Open
telamon opened this issue May 17, 2020 · 12 comments
Open

Vanilla node fails to import #69

telamon opened this issue May 17, 2020 · 12 comments

Comments

@telamon
Copy link

telamon commented May 17, 2020

$ node
Welcome to Node.js v13.2.0.
Type ".help" for more information.
> require('svgdom')
Thrown:
Error: No valid exports main found for '.../node_modules/svgdom'
    at resolveExportsTarget (internal/modules/cjs/loader.js:611:9)
    at applyExports (internal/modules/cjs/loader.js:492:14)
    at resolveExports (internal/modules/cjs/loader.js:541:12)
    at Function.Module._findPath (internal/modules/cjs/loader.js:643:22)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:941:27)
    at Function.Module._load (internal/modules/cjs/loader.js:847:27)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (internal/modules/cjs/helpers.js:69:18) {
  code: 'MODULE_NOT_FOUND'
}
@Fuzzyma
Copy link
Member

Fuzzyma commented May 17, 2020

Did you install it?

$ node
Welcome to Node.js v13.12.0.
Type ".help" for more information.
> require('svgdom')
{
  defaults: Object [Module] {
    fontSize: [Getter],
    fontFamily: [Getter],
    fontDir: [Getter],
    fontFamilyMappings: [Getter]
  },
  Attr: [Function: Attr],
  CharacterData: [Function: CharacterData],
  Comment: [Function: Comment],
  CustomEvent: [Function: CustomEvent],
  DOMImplementation: {
    hasFeature: [Function: hasFeature],
    createDocumentType: [Function: createDocumentType],
    createDocument: [Function: createDocument],
    createHTMLDocument: [Function: createHTMLDocument]
  },
  Document: [Function: Document],
  DocumentFragment: [Function: DocumentFragment],
  Element: [Function: Element],
  Event: [Function: Event],
  EventTarget: [Function: EventTarget],
  Node: [Function: Node] {
    ELEMENT_NODE: 1,
    ATTRIBUTE_NODE: 2,
    TEXT_NODE: 3,
    CDATA_SECTION_NODE: 4,
    ENTITY_REFERENCE_NODE: 5,
    ENTITY_NODE: 6,
    PROCESSING_INSTRUCTION_NODE: 7,
    COMMENT_NODE: 8,
    DOCUMENT_NODE: 9,
    DOCUMENT_TYPE_NODE: 10,
    DOCUMENT_FRAGMENT_NODE: 11,
    NOTATION_NODE: 12
  },
  NodeFilter: [Function: NodeFilter] {
    FILTER_ACCEPT: 1,
    FILTER_REJECT: 2,
    FILTER_IGNORE: 4,
    SHOW_ALL: -1,
    SHOW_ELEMENT: 1,
    SHOW_TEXT: 4,
    SHOW_ENTITY_REFERENCE: 16,
    SHOW_ENTITY: 32,
    SHOW_PROCESSING_INSTRUCTION: 64,
    SHOW_COMMENT: 128,
    SHOW_DOCUMENT: 256,
    SHOW_DOCUMENT_TYPE: 512,
    SHOW_DOCUMENT_FRAGMENT: 1024,
    SHOW_NOTATION: 2048
  },
  Text: [Function: Text],
  Window: [Function: Window],
  HTMLElement: [Function: HTMLElement],
  HTMLImageElement: [Function: HTMLImageElement],
  HTMLLinkElement: [Function: HTMLLinkElement],
  HTMLParser: [Function: HTMLParser],
  HTMLScriptElement: [Function: HTMLScriptElement],
  elementAccess: {
    getElementsByTagName: [Function: getElementsByTagName],
    getElementsByTagNameNS: [Function: getElementsByTagNameNS],
    getElementsByClassName: [Function: getElementsByClassName]
  },
  ParentNode: {
    matchWithScope: [Function: matchWithScope],
    query: [Function: query],
    querySelectorAll: [Function: querySelectorAll],
    querySelector: [Function: querySelector],
    prepend: [Function: prepend],
    append: [Function: append],
    replaceChildren: [Function: replaceChildren]
  },
  SVGElement: [Function: SVGElement],
  SVGGraphicsElement: [Function: SVGGraphicsElement],
  matrixFactory: [Function: matrixFactory],
  SVGMatrix: [Function: SVGMatrix],
  SVGPathElement: [Function: SVGPathElement],
  SVGPoint: [Function: SVGPoint],
  SVGSVGElement: [Function: SVGSVGElement],
  SVGTextContentElement: [Function: SVGTextContentElement],
  setFontDir: [Function: setFontDir],
  setFontFamilyMappings: [Function: setFontFamilyMappings],
  preloadFonts: [Function: preloadFonts],
  getConfig: [Function: getConfig],
  getFonts: [Function: getFonts],
  config: {
    setFontDir: [Function: setFontDir],
    setFontFamilyMappings: [Function: setFontFamilyMappings],
    preloadFonts: [Function: preloadFonts],
    getConfig: [Function: getConfig],
    getFonts: [Function: getFonts]
  },
  createDocument: [Function: createDocument],
  createHTMLDocument: [Function: createHTMLDocument],
  createSVGDocument: [Function: createSVGDocument],
  createWindow: [Function: createWindow],
  createHTMLWindow: [Function: createHTMLWindow],
  createSVGWindow: [Function: createSVGWindow]
}

@telamon
Copy link
Author

telamon commented May 18, 2020

Sorry for the stressed issue report,
Yeah i installed svg-dom, I got my test-code working yesterday
by directly including:

require('./node_modules/svgdom/main-require.js')

I suspect that there's a misconfiguration in package.json but it's a bummer that the bug doesn't reproduce on your end. Could also relate to our node-versions i guess.

@Fuzzyma
Copy link
Member

Fuzzyma commented May 18, 2020

Yes it will be quite sure the node version. However, all the stuff is backwards compatible. The main entry in the package.json points to main-require.cjs and that key is resolved in old node versions too.

@telamon
Copy link
Author

telamon commented May 18, 2020

Yeah i agree that it "should", the exports look syntactically correct comparing to the docs:
https://nodejs.org/api/esm.html#esm_approach_2_isolate_state

But then again backwards-compatiblity "should" include the version i'm running as well - honestly I'm a bit intrigued by this issue, it shouldn't exist.

@Fuzzyma
Copy link
Member

Fuzzyma commented May 18, 2020

Its strange. If you have a look at #60 you can see that the code seems to work with node 12 or even node 8. Maybe it is a bug specific to your version? Or something different is going on.
You could try to use excatly my version to see if the error persists.

@henrypenny
Copy link

(node: v13.2.0)

When I use :

import { createSVGWindow } from 'svgdom';

I get:

internal/modules/esm/default_resolve.js:94
  let url = moduleWrapResolve(specifier, parentURL);
            ^

Error: Cannot resolve package main '[object Object]' in /node_modules/svgdom/package.json, imported from 
src/image.js
    at Loader.resolve [as _resolve] (internal/modules/esm/default_resolve.js:94:13)
    at Loader.resolve (internal/modules/esm/loader.js:74:33)
    at Loader.getModuleJob (internal/modules/esm/loader.js:148:40)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:41:40)
    at link (internal/modules/esm/module_job.js:40:36) {

@dasheck0
Copy link

dasheck0 commented Jan 2, 2021

Same. I use typescript and while it compiles it gets an error: window is not defined when using the code in the README.md file. VSCode is also not able to resolve the package at all. It gives an error Cannot find module 'svgdom' or its corresponding type declarations.ts(2307). I added custom typings for this package just in case this is just a formal error. But it did not help. Strange

@Fuzzyma
Copy link
Member

Fuzzyma commented Jan 2, 2021

I am using svg.js with typescript right now and have no problems whatsoever. If window is not defined in your typescript you might want to run typescript with the dom lib enabled?

@larshp
Copy link

larshp commented Jan 11, 2021

as far as I can tell, svgdom does not include typescript type definitions?

@Fuzzyma
Copy link
Member

Fuzzyma commented Jan 11, 2021

I obviously mixed up the repositories there...

No, svgdom has no typescript definitions but you could just use the dom lib which typescripts provide. Its a dom after all ^^

@larshp
Copy link

larshp commented Jan 11, 2021

the issue for me is the createSVGWindow function, I've worked around the issue by @ts-ignore'ing the import,

// @ts-ignore, https://github.com/svgdotjs/svgdom/issues/69
import {createSVGWindow} from "svgdom";
const window = createSVGWindow();

@altano
Copy link

altano commented Aug 28, 2023

@larshp please see #110

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants