Coder Social home page Coder Social logo

Comments (13)

falsandtru avatar falsandtru commented on May 15, 2024

Perhaps you need to use global variables, such as spica, localsocket and pjax-api for endpoints. I am currently not using Browserify but I'm considering using it.

from pjax-api.

Flobin avatar Flobin commented on May 15, 2024

Thank you for the quick reply! So like this?

import spica from 'spica';
import localsocket from 'localsocket';
import Pjax from 'pjax-api';

It seems I’m still getting the same error.

from pjax-api.

falsandtru avatar falsandtru commented on May 15, 2024

https://github.com/thlorenz/browserify-shim may resolve your problem.

from pjax-api.

Flobin avatar Flobin commented on May 15, 2024

So I’m using browserify-shim and I’ve set it up like this:

main.js:

var spica = require('spica');
var localsocket = require('localsocket');
import Pjax from 'pjax-api';

package.json:

"browserify": {
  "transform": [
    [
      "babelify",
      {
        "presets": [
          "es2015"
        ]
      }
    ],
    "browserify-shim"
  ]
},
"browserify-shim": {
  "./node_modules/spica/dist/spica.min.js": "global:spica",
  "./node_modules/localsocket/dist/localsocket.min.js": "global:localsocket"
}

gulpfile.js:

gulp.task('scripts', function () {
  var b = browserify({
    entries: ['src/scripts/modernizr.js', 'src/scripts/main.js'],
    debug: true
  }).transform(babelify, { presets: ["latest"] });

  return b.bundle()
    .pipe(source('main.js'))
    .pipe(buffer())
    .pipe(sourcemaps.init({loadMaps: true}))
        // Add transformation tasks to the pipeline here.
        // .pipe(uglify())
        .on('error', gutil.log)
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('build/js/'));
});

Now I get the error: pjax-api.js:24Uncaught Error: Cannot find module 'spica'. I guess this is not the correct way to require or import spica/localsocket?

from pjax-api.

falsandtru avatar falsandtru commented on May 15, 2024

I published the new version now. pjax-api has been using Browserify since 3.4.0, also the depended libraries too. You should be able to build it.

from pjax-api.

Flobin avatar Flobin commented on May 15, 2024

@falsandtru thank you so much for all your help and hard work!

I’ve updated the above code, still using browserify-shim, but with the new versions of spica, localsocket, and pjax-api. Main.js only has the import statement for pjax-api. The import seems to be working correctly!

However, I’m getting a different error now:

tinymce.js:41629 Uncaught TypeError: _pjaxApi2.default is not a constructor
at Object.5.jquery (http://localhost:8000/static/articles/build/js/main.js:60706:1)
at s (http://localhost:8000/static/articles/build/js/main.js:1:254)
at e (http://localhost:8000/static/articles/build/js/main.js:1:425)
at http://localhost:8000/static/articles/build/js/main.js:1:443

This is main.js.

from pjax-api.

falsandtru avatar falsandtru commented on May 15, 2024

Thanks for the report. That is because __esModule flag is missing. I fixed it in 3.4.1. The same is true for other depended libraries.

from pjax-api.

Flobin avatar Flobin commented on May 15, 2024

@falsandtru thank you again!

I’ve updated to the new versions, but am still getting an error:

My code and the error are here and the full main.js is here. Maybe it's an issue with how I'm doing the require statements?

from pjax-api.

falsandtru avatar falsandtru commented on May 15, 2024

Probably you need to update other libraries such as spica and localsokcet. What version of libraries are you using?

from pjax-api.

Flobin avatar Flobin commented on May 15, 2024

I’m using these versions:

Robins-MacBook-Pro:articles robin$ npm update spica localsocket pjax-api
[email protected] /Users/robin/work/2016-06-04_togethere/togethere/articles/static/articles
├── [email protected]
├── [email protected]
└── [email protected]

(forgot to update package.json in that earlier gist, sorry!)

from pjax-api.

falsandtru avatar falsandtru commented on May 15, 2024

Now you cannot use browserify-shim for spica and localsocket. So you need to remove the following code.

  "browserify-shim": {
    "./node_modules/spica/dist/spica.min.js": "global:spica",
    "./node_modules/localsocket/dist/localsocket.min.js": "global:localsocket"
  }

from pjax-api.

Flobin avatar Flobin commented on May 15, 2024

I’ve uninstalled browserify-shim and made sure it’s not being used, but it looks like I’m still getting the same issue... code here.

Sorry to be such a pain in the ass. Maybe I’m doing things wrong in the way I require the libraries?

from pjax-api.

falsandtru avatar falsandtru commented on May 15, 2024

Seems like this is a difficulty of Browserify. We cannot directly bundle another browserified library. If you know another library which bundled browserified library, let me know that library.

from pjax-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.