flickity icon indicating copy to clipboard operation
flickity copied to clipboard

ES6 import and dependency paths

Open SukhKalsi opened this issue 10 years ago • 4 comments

Hello

I understand posting an issue requires a reduced test case however this is a very specific issue which Codepen cannot reproduce - if this is an issue in itself please let me know.

My directory structure is like so

| package.json
| node_modules/
| src/
    |-- main.js
    |-- components/
        |-- carousel
            |-- carousel.js
            |-- carousel.scss
            |-- node_modules/
                |-- flickity/
                |-- flickity-as-nav-for/
                |-- flickity-imagesloaded/

So I'm looking to integrate Flickity as an ES6 import within carousel.js like so: import Flickity from './node_modules/flickity/js/index';

However the issue arrises with ev-emitter whereby its attempting to locate the path to the route of my project as oppose to the current component path.

Error on fetch for ev-emitter/ev-emitter.js

Full error log:

{ [Error: Error on fetch for ev-emitter/ev-emitter.js at file:///ev-emitter/ev-emitter.js
    Loading src/components/carousel/node_modules/flickity/js/flickity.js
    Loading src/components/carousel/node_modules/flickity/js/index.js
    Loading src/components/carousel/carousel.js
    Loading src/main.js
    ENOENT: no such file or directory, open '/ev-emitter/ev-emitter.js']
  originalErr: 
   { [Error: ENOENT: no such file or directory, open '/ev-emitter/ev-emitter.js']
     errno: -2,
     code: 'ENOENT',
     syscall: 'open',
     path: '/ev-emitter/ev-emitter.js' } }

I'm using the following:

Node: v4.4.7 NPM: 2.15.8

And the package.json:

{
  "name": "carousel",
  "version": "1.0.0",
  "description": "Carousel component",
  "main": "carousel.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "flickity": "^2.0.4",
    "flickity-as-nav-for": "^2.0.1",
    "flickity-imagesloaded": "^2.0.0"
  }
}

SukhKalsi avatar Oct 14 '16 12:10 SukhKalsi

Looks like the loader is looking for file:///ev-emitter/ev-emitter.js but that should be src/components/carousel/node_modules/ev-emitter/ev-emitter.js. you'll need to add some config option so that dependencies are searched for with relative paths.

desandro avatar Oct 14 '16 14:10 desandro

I believe so too - will close this as its more of an issue within this environment as oppose to an issue with Flickity.

SukhKalsi avatar Oct 16 '16 20:10 SukhKalsi

@desandro do you know what that config looks like?

linnett avatar Oct 18 '16 14:10 linnett

Sorry, nope. As I do not have access to your or @SukhKalsi's development environment, I have no way of knowing where the mix up is.

desandro avatar Oct 19 '16 16:10 desandro