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

TypeError on Import #121

Open
citizen00147 opened this issue Feb 21, 2023 · 8 comments
Open

TypeError on Import #121

citizen00147 opened this issue Feb 21, 2023 · 8 comments

Comments

@citizen00147
Copy link

Hey there,

First off, love this library! I'm using the vanilla version and I'm getting a type error after importing: Uncaught TypeError: The specifier “@neodrag/vanilla” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “../” or “/”.

I think it's an issue with the path. I solved this by changing import { Draggable } from "@neodrag/vanilla"; to import { Draggable } from "../node_modules/@neodrag/vanilla/dist/min/index.js"; Once I changed that my object became draggable!

I've included a few screenshots of my test project below.

TypeError
TypeErrorHTML
TypeErrorJS

@PuruVJ
Copy link
Owner

PuruVJ commented Feb 21, 2023

What bundler are you using?

@citizen00147
Copy link
Author

What bundler are you using?

Ah, so that must be my issue then? I'm not using a bundler.

@PuruVJ
Copy link
Owner

PuruVJ commented Feb 22, 2023

Ah! Wait, then how are you importing @neodrag/vanilla directly without a bundler?

If ur using it raw in a browser environment, maybe using the CDN directly could be worth it? https://esm.sh/@neodrag/[email protected]

@stepanjakl
Copy link

Hello @PuruVJ,

I would like to expand on this issue and ask if you could release a UMD version of the library, thereby allowing access through CDNs such as UNPKG?

@stepanjakl
Copy link

I came up with a seperate solution to generate the UMD file using the Rollup compiler. Possibly it could make us of the NX package as well. It's just a first shot for now.

// neodrag/packages/vanilla/rollup.config.js

import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';

const config = {
	input: 'src/index.ts',
	output: {
		name: 'Draggable',
		format: 'umd',
		file: 'dist/index.js'
	},
	plugins: [ typescript(), commonjs(), resolve(), /* terser() */ ]
};

export default config;
// package.json

"scripts": {
        ...
	"compile:umd": "rollup --config"
}

@PuruVJ
Copy link
Owner

PuruVJ commented Mar 20, 2023

Hey! Sorry for the late reply.

Regarding your problem, is there anything stopping you from using import { Draggable } from 'https://unpkg.com/@neodrag/[email protected]/dist/min/index.js'?

@stepanjakl
Copy link

@PuruVJ I am embedding scripts directly on the page without a compiler. If I use the import statement on the client/browser side I get this error: Uncaught SyntaxError: Cannot use import statement outside a module

@PuruVJ
Copy link
Owner

PuruVJ commented Mar 20, 2023

Ah! I'll add a UMD in that case

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

3 participants