Skip to content

Source Maps Failing in Dev #352

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

Closed
raupie opened this issue Jul 19, 2018 · 3 comments · Fixed by #356
Closed

Source Maps Failing in Dev #352

raupie opened this issue Jul 19, 2018 · 3 comments · Fixed by #356
Labels

Comments

@raupie
Copy link

raupie commented Jul 19, 2018

When using .enableSourceMaps(!Encore.isProduction()) I am getting a Uncaught SyntaxError: Unexpected token : error.

When I set source maps to false, it goes away.

Missing break line?

@Lyrkan
Copy link
Collaborator

Lyrkan commented Jul 19, 2018

More context based on what @raupie put on Slack:

  • He's using Webpack 4
  • The output file contains the following lines:
// (...)
}]);
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ(...)ZVJvb3QiOiIifQ==(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["_tmp_shared"],{
"../../../tmp/tmp-92SW7NIosJEwEF.tmp":
(function(module, exports, __webpack_require__) {
__webpack_require__( "./assets/js/global.js")
})
// (...)

It seems that a line-break is missing before (window["webpackJsonp"] = window["webpackJsonp"] || []).push([["_tmp_shared"],{ which causes it to be part of the source-map comment...

@raupie Do you have any additional info that could help reproducing the issue? For instance the content of your webpack.config.js?

@Lyrkan Lyrkan added the Bug Bug Fix label Jul 19, 2018
@raupie
Copy link
Author

raupie commented Jul 19, 2018

webpack.config.js

const Encore = require('@symfony/webpack-encore');
const CopyWebpackPlugin = require('copy-webpack-plugin');

Encore
    .enableSingleRuntimeChunk()
    // the project directory where all compiled assets will be stored
    .setOutputPath('web/assets/')
    // the public path used by the web server to access the previous directory
    .setPublicPath('/assets')
    // empty the outputPath dir before each build
    .cleanupOutputBeforeBuild()
    // allow legacy applications to use $/jQuery as a global variable
    .autoProvidejQuery()
    // create hashed filenames (e.g. app.abc123.css)
    .enableVersioning(false)
    // trace bugs to original files
    .enableSourceMaps(false)
    //.enableSourceMaps(!Encore.isProduction())
    // allow sass/scss files to be processed
    .enableSassLoader()
    // Copy image assets to web folder
    .addPlugin(new CopyWebpackPlugin([{
        from: './assets/images/',
        to: 'images/'
    }]))
    // Front End Configuration
    // Global Framework Dependencies
    .createSharedEntry('global', './assets/js/global.js')
    // Site Theme
    .addStyleEntry('main', './assets/css/main.css')
    // Homepage Feature
    .addStyleEntry('homepage', './assets/css/homepage.css')
    // Forms Feature
    .addEntry('forms', './assets/forms/app.js')
    // Product Feature
    .addEntry('prodpage', './assets/js/prod-page.js')
;

module.exports = Encore.getWebpackConfig(); 

global.js

// libraries
require('jquery');
require('what-input');
require('foundation-sites');

// css
require('../css/global.scss');

// initiate foundation framework
$(document).foundation();

prod-page.js

// require css
require('datatables.net-zf/css/dataTables.foundation.css');
require('datatables.net-responsive-zf/css/responsive.foundation.css')
require('../css/prod-page.css');

// require datatables library
require('datatables.net-zf')();
require('datatables.net-responsive-zf')();

$(document).ready(function(){
    $('#configurations').DataTable({responsive: true});
    //  console.log('this is where the table is supposed to get inited');
});

Trying to use foundation + datatables. Compile is now failing with ModuleNotFoundError: Module not found: Error: Can't resolve '../images/sort_asc.png' in '/var/www/html/project/ezplatform/node_modules/datatables.net-zf/css'

@Lyrkan
Copy link
Collaborator

Lyrkan commented Jul 19, 2018

I did a quick check and could reproduce it with the following config and an empty shared.js file:

// webpack.config.js
const Encore = require('@symfony/webpack-encore');

Encore
    .disableSingleRuntimeChunk() // Doesn't seem to matter
    .setOutputPath('build')
    .setPublicPath('/build')
    .cleanupOutputBeforeBuild()
    .enableSourceMaps(!Encore.isProduction())
    .createSharedEntry('shared', './shared.js')
;

module.exports = Encore.getWebpackConfig();

Extract from the final shared.js in dev mode:

//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJ(...)2VSb290IjoiIn0=/******/ (function(modules) { // webpackBootstrap

@Lyrkan Lyrkan added the HasPR label Jul 20, 2018
@Lyrkan Lyrkan added this to the Webpack 4 integration milestone Jul 23, 2018
weaverryan added a commit that referenced this issue Jul 23, 2018
This PR was merged into the master branch.

Discussion
----------

Fix shared entry file when source maps are enabled

This PR fixes #352.

When source maps are enabled, the original shared entry file ends with a commented line.

This is an issue when the "_tmp_shared" entry is appended to it since its first line then becomes part of that comment.

Commits
-------

278d992 Fix shared entry file when source maps are enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants