flatiron / director

a tiny and isomorphic URL router for JavaScript
http://github.com/flatiron/director
MIT License
5.61k stars 483 forks source link

Not compatible with webpack2 #349

Open ibio opened 7 years ago

ibio commented 7 years ago

When I upgraded to webpack2/npm(4.1.2), it raised the following runtime error: Uncaught TypeError: this.configure is not a function at Object.exports.Router (webpack:///./~/director/lib/director/router.js?:181) at init (webpack:///./app/view/router.jsx?:58) at eval (webpack:///./app/view/router.jsx?:121) at Object.212 (app.js:2) at n (vendor.js:1) at eval (webpack:///./app/main.js?:5) at Object.529 (app.js:9) at n (vendor.js:1) at window.webpackJsonp (vendor.js:1) at app.js:1

I figured it out that webpack2 somehow did not recognize the ./build path, instead it used ./lib path, which is declared in package.json("main": "./lib/director"). I believe there are some issues because what's in the ./lib is not complete code and we can only use the code in ./build path.

However, I am wondering why it worked fined with webpack1. Plese let me know what happened here. thanks :)

pscottdevos commented 7 years ago

Can confirm. Having the same problem when upgrading to webpack 2.2.1

statianzo commented 7 years ago

Webpack 1 used the browserify main field in package.json. That behavior was removed in Webpack 2. If you want to keep that behavior, add it back to your webpack config in resolve.mainFields. Otherwise, add a resolve.alias for director.

creage commented 7 years ago
import { Router } from 'director/build/director';
...
...
...
const router = new Router().init();

this worked for me on Webpack2

jeremyk commented 7 years ago

This works. But when I try to server render I get a document is not defined error. Seems like this didn't happen when importing the other way.

javidan commented 7 years ago

Same Issue for me. When using

import { Router } from 'director';

Getting error init is not a function

if use

import { Router } from 'director/build/director';

Server side rendering is not working. Getting error document is not defined

statianzo commented 7 years ago

@javidan did you test my suggestion?

ClearedFram3 commented 5 years ago

@javidan do you know the reason importing from 'director/build/director' works?

statianzo commented 5 years ago

@ClearedFram3 see my comment above. Webpack 1 used to read the browserify package.json setting that specified director/build/director. Webpack 2 dropped that behavior.

qman19791123 commented 5 years ago

Correct import introduction

import {Router} from 'director/build/director.js'