How to fix

Option a: installing the module + all of it's dependencies with composer (preferred solution)
composer require drupal/csv_serialization

Option b: only install the dependencies trough composer.
composer require league/csv

Original report:

I have composer installed globally.
The module is installed in:

<drupal root>/modules/contrib/csv_serialization

I changed my current working directory to:

<drupal root>/modules/contrib/csv_serialization

I then ran the command:

composer install

I can verify there is now the following folders:

<drupal root>/modules/contrib/csv_serialization/vendor/league/csv/

When I go to Extend page and enable the Serialization (CSV) module I get the following message:

CSV Serialization requires the League\Csv library.

Am I doing something wrong?

Alternative workaround

See comment #25 for a workaround using the Ludwig module instead of Composer directly.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jlab created an issue. See original summary.

jlab’s picture

Issue summary: View changes
ronaldpunt’s picture

Why it's so hard to get this stuff working? How to install this library. Why no simple tutorial?

grasmash’s picture

Status: Active » Closed (won't fix)

Please follow the instructions here: https://www.drupal.org/docs/develop/using-composer/using-composer-with-d...

The steps that you used are incorrect. You should not be executing composer commands in the module directory. You must execute them from your repository's root directory to modifying the top-level composer.json.

NewZeal’s picture

This kind of problem can be resolved simply by running:

composer config repositories.drupal composer https://packages.drupal.org/8

And then:

composer require drupal/name_of_library

And if that fails, delete composer.lock in root directory and run the second command again.

Those instructions should be mandatory in every module that requires composer.

NewZeal’s picture

Status: Closed (won't fix) » Active

Please add full instructions to README:

composer config repositories.drupal composer https://packages.drupal.org/8

And:

composer require drupal/csv_serialization

And if that fails, delete composer.lock in root directory and run the second command again.

jlab’s picture

Thanks New Zeal and grashmash,

I am not very familiar with composer and still have to go through the whole learning curve. Thanks for clearing things up.

And the two composer lines mentioned above would have been very usefull in the README.

drupal_hack’s picture

I am on a private network with no Internet connection. Is there any way to install the League/Csv library without an Internet connection?

jnicola’s picture

I'm running into the same issue, and the link you provide does not actual contain the information necessary to make this work. What you're doing is dismissive and not acceptable. You need more substantial basic notes on how to make this work. There are a multitude of tickets regarding this issue on this project. It really needs to get sorted better.

Granted, I'd say this is a deficiency in D8 core and libraries (libraries has always been a pain in the ass) but since you leverage libraries, you take on that burden.

In docroot:
composer required league/csv
composer install

Worked for me. I was still having issues though as others have had.

grasmash’s picture

This module requires that you use Composer to manage your Drupal site dependencies.

The exact instructions required for managing Drupal site dependencies via Composer will vary from site to site, depending on your directory structure and configuration.

The CSV Serialization module is not to proper place to provide these instructions. Your application's Composer configuration is a higher level concern. Similarly, CSV Serialization would not be the proper place to provide instructions for LAMP stack configuration.

The CSV Serialization module only checks to see if the required PHP classes are available. The libraries module is not used.

Using Composer to manage Drupal site dependencies is the intended to cover this topic. If you feel that it requires work, please use the discuss tab on that page to make a suggestion.

The linked documentation says the following under the heading "Using Composer to manage Drupal site contributed dependencies":

Using Composer to manage contributed dependencies for a Drupal site is unique. It requires some Drupal-specific configuration in your composer.json file, namely:

It goes on to answer "How can I add Drupal modules and themes to my site with composer?":

To download Drupal modules or themes for your site with composer, enter the following command at the root of your Drupal install:

$ composer require drupal/
For example:

$ composer require drupal/token

These instructions apply to all modules, including csv_serialization.

If you follow the instructions for Using Composer to manage Drupal site dependencies, and then download this module in the prescribed way (composer require drupal/csv_serialization) then Composer will automatically download and autoload the league/csv package for you.

chrotto’s picture

You made my day New Zeal, after updating core this module failed. When I found #5, I solved it in one minute.

borisson_’s picture

#5

And if that fails, delete composer.lock in root directory and run the second command again.

That is terrible advice, deleting composer.lock is not great, especially when suggesting people install packages without version constraints. That will 100% lead to unintended major version upgrades.

Always use $ composer require "drupal/module:version.x" instead, for this module that's $ composer require "drupal/csv_serialization:1.x". Deleting the composer.lock means that ALL dependencies are going to be updated to their latest releases, that might mean major updates when you don't want those to happen.

I know that usage of composer is something that scares some people, it might be useful to promote conductor here as well. That project was intended to make it easier to work with composer: https://github.com/mglaman/conductor

Anyway, since there's a couple of issues in this queue that talk about this, I think we should open a new issue to update the README.txt with documentation and close all other issues as duplicates of that one.

ndf’s picture

Status: Active » Needs review

With drupal 8.3.x and higher, you can can/should install this module from the drupal docroot like this:
composer require drupal/csv_serialization

The dependency League\Csv will automatically be downloaded.

borisson_’s picture

Category: Bug report » Support request
Status: Needs review » Active

This shouldn't be Needs review, there's no patch. Back to active.

ashwinsh’s picture

#9: works for me, thank you @jnicola.

In docroot:
composer require league/csv
composer install

Thank you,
AshwinSh

borisson_’s picture

Issue summary: View changes

I updated the IS with what to do.

hiramanpatil’s picture

#6 worked for me.

Thanks

romel.adodis’s picture

Those who are new to Drupal 8,
Install the composer normally

Step 1:
Modify the composer.json file in your docroot and add the below line under "require" section(append below line if some other library/module already exist)

"require": {
"drupal/csv_serialization": "^1.0"
},

Step 2:
Run "composer require drupal/csv_serialization" from the "docroot directory" in command prompt.

-------------

For "Windows Acquia dev desktop users" if Composer command is not working

try the below in the cmd,
1) cd "sites_doc_root_dir"
2) php.exe "c:/Program Files (x86)/DevDesktop/tools/composer.phar" require drupal/csv_serialization

ashwinparmar’s picture

Problem: Error visible while installation of module: 'CSV Serialization requires the League\Csv library.'
Simple solution: Just put single line in file: modules\contrib\csv_serialization\src\Encoder\CsvEncoder.php

<?php

namespace Drupal\csv_serialization\Encoder;

use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use League\Csv\Writer;
use League\Csv\Reader;
use SplTempFileObject;
use Drupal\Component\Utility\Html;
use Drupal\Component\Serialization\Exception\InvalidDataTypeException;

require (drupal_get_path('module', 'csv_serialization') . '/vendor/autoload.php');

/**
 * Adds CSV encoder support for the Serialization API.
 */
class CsvEncoder implements EncoderInterface, DecoderInterface {

It will fixed the issue and working fine.
Issue is because of library was not loaded, that's why checking in module.install file that class was exists or not.

colan’s picture

Status: Active » Needs work

#19: Composer should be installing the library in the Drupal root directory's vendor subdirectory. It should not be within the module directory.

Are you running Composer from the Drupal root directory as you should be?

grasmash’s picture

Status: Needs work » Closed (works as designed)

@colan is correct.

The patch in #19 is invalid because the league/csv library should not be in the module directory. It should be in the root vendor directory. It is incorrect to cd into `modules/contrib/csv_serialization` and run `composer install`. This is not the proper way to manage Drupal module dependencies via composer because the dependency will not be added to Drupal's autoloader, and you'll encounter the exact problem described in the issue summary.

Installing Drupal module dependencies via Composer requires a number of Drupal specific composer configurations to be in your composer.json file. The commands in #6 represent one portion of that required configuration. You can read more about how to set up your root composer.json file at Using Composer to manage Drupal site dependencies.

If configured correctly, your composer.json will instruct composer to do the following when `composer install` is executed from the project root directory:

  • Download the module from drupal's packagist server
  • Place the module in docroot/modules/contrib
  • Place the library in vendor
  • Autoload the library's classes

Composer is complex, and the method of implementing it for Drupal applications is nuanced and even more complex. I sympathize with everyone struggling in this issue. However, the solution is to implement the correct composer configuration. No change to be module will solve this problem.

As a side thought, perhaps we should make a composer plug-in that validates a composer.json file and asserts that all Drupal specific configuration is correct.

grasmash’s picture

Hopefully this will be helpful. It is an example composer.json file for an application that includes only Drupal core and this module. Please note that in this particular example, the docroot is a subdirectory of the repository root. This may not be the case for your Drupal application.

Specifically, the directory structure for this example is:

-  docroot
    - core
    - modules
        - contrib
            - csv_serialization
-  vendor
    - league
        - csv
-  composer.json

Here is the example composer.json file:

{
    "license": "proprietary",
    "type": "project",
    "repositories": {
        "drupal": {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    },
    "require": {
        "drupal/core": "^8.0",
        "drupal/csv_serialization": "^1.0"
    },
    "require-dev": {},
    "extra": {
        "installer-paths": {
            "docroot/core": ["type:drupal-core"],
            "docroot/modules/contrib/{$name}": ["type:drupal-module"],
            "docroot/modules/custom/{$name}": ["type:drupal-custom-module"],
            "docroot/profiles/contrib/{$name}": ["type:drupal-profile"],
            "docroot/profiles/custom/{$name}": ["type:drupal-custom-profile"],
            "docroot/themes/contrib/{$name}": ["type:drupal-theme"],
            "docroot/themes/custom/{$name}": ["type:drupal-custom-theme"],
            "docroot/libraries/{$name}": ["type:drupal-library"],
            "drush/contrib/{$name}": ["type:drupal-drush"]
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

To correctly install all packages, you should run`composer install` from the repository's root directory, one directory above the docroot.

Never run any composer commands in any other directory, like the csv_serialization directory.

akmalfikri’s picture

Tried both #5 and #9 but it seems that league/csv have been updated into 9.0 version, which unsatisfiable for csv_serialization which requires 7.1^.

In my vendor folder, league/csv folder existed, but Drupal still cannot detect the folder. Need this ASAP.

scott.whittaker’s picture

Been banging my head against this issue all morning, finally solved it.

In my case, all my D8 sites using composer have the composer stuff one level back from the webroot, with the webroot in a folder called "web". To install most modules and libraries you need to go back from the webroot to the parent composer folder and do "composer require drupal/modulename". This is working for all modules except this one.

In my case, even though composer would download the module using this method, it could not be enabled due to the "CSV Serialization requires the League\Csv library." error.

In order to install the module, I had to composer require it from the webroot, not the normal composer location.

drupalnesia’s picture

MANUAL INSTALLATION OF league-csv LIB
----------------------------------------

  1. Install ludwig module. Go to Reports - Packages, you will see the download link of league-csv lib
  2. Download league-csv lib from above link, https://codeload.github.com/thephpleague/csv/legacy.zip/fa8bc05f64eb6c66...
  3. Extract the lib under "public_html/modules/csv_serialization/lib/league-csv/8.2.2" folder. So you will see:
    csv_serialization/lib/league-csv/8.2.2
    csv_serialization/lib/league-csv/8.2.2/autoload.php .... and so on
HongPong’s picture

@drupalisme this worked brilliantly for me on Pantheon for a client. Thank you so much! We didn't have to break Pantheon's Dashboard upgrades to pull this off.

HongPong’s picture

Issue summary: View changes
chrisindallas’s picture

I followed @drupalisme instructions using ludwig and while under Reports -> Packages is says league/csv 8.2.2 is installed, when I try to enable Serialization (CSV) 8.x-1.4+3-dev I still get the error at the top of the Extend page that "CSV Serialization requires the League\Csv library." Am I missing a step? I tried it with and without the addition to modules\contrib\csv_serialization\src\Encoder\CsvEncoder.php mentioned in #19.

This is a site that was created without composer and I ran into php version trouble installing composer.

drupalnesia’s picture

@chrisindallas: try to clear Drupal Cache. Better use Flush All Caches which come from https://www.drupal.org/project/admin_toolbar. This function available at Drupal 8 Icon - Flush All Caches.

kentr’s picture

@chrisindallas:

I had the same problem. drush cr solved it for me.

@drupalisme and Ludwig module saved the day!

oheller’s picture

We don't have control over the webroot/composer.json file. We need to be able to add this to the sites/default/composer.json file. Our sites vendor folder is at sites/default/vendor.

I would expect to be able to run composer require csv_serialization inside the default folder and have it installed in the correct place. Then I would expect it to be able to find the League\Csv inside the vendor folder at sites/default/vendor.

If none of that is possible I'd like to be able to move it into my custom modules folder, so that composer doesn't mess with it after it's built. When I do move it I get the file not found error even after clearing the cache.

jeremyr’s picture

In case anyone else runs into this:

If you're installing with composer and get an error similar to this:

Problem 1
    - Conclusion: don't install drupal/csv_serialization 1.4.0
    - Conclusion: remove league/csv 9.3.0
    - Installation request for drupal/csv_serialization ^1.4 -> satisfiable by drupal/csv_serialization[1.x-dev, 1.4.0].

It's because this module requires an older version of league/csv than what composer is fetching. You can fix this by running the below command first:

composer require league/csv:^8.0

I assume in future versions this wont be a problem.

aiphes’s picture

According to #32 , I installed league CSV before but it's in conflict with another module like migrate CSV:

 Problem 1
    - Installation request for drupal/migrate_source_csv ^3.1 -> satisfiable by drupal/migrate_source_csv[3.x-dev, 3.1.0].
    - Can only install one of: league/csv[9.x-dev, 8.2.3].
    - Can only install one of: league/csv[9.x-dev, 8.2.3].
    - Can only install one of: league/csv[9.x-dev, 8.2.3].
    - Conclusion: install league/csv 9.x-dev
    - Installation request for league/csv (locked at 8.2.3, required as ^8.0) -> satisfiable by league/csv[8.2.3].

So I think I would to choose to install one of them but not both.On D8.7.7 fresh Composer install.

vipin.mittal18’s picture

I used following command to resolve the dependency of "League/csv" on Drupal 8.7.5 at web root location.

composer require drupal/csv_serialization

It works!

ddhuri’s picture

#34 worked for me.

Thanks

hunsly’s picture

Flush All Caches method worked. Thanks

mtdaveo’s picture

3/30/20, 12 pm PST

Updated from Core 8.8.2 to 8.8.4 today.

Manual uploading (FTP) of the two modules/structure below...

#25 worked like a charm yesterday. Now today I'm having a helluva time enabling Views Data Export module...

"The "data_export" plugin does not exist. Valid plugin IDs for Drupal\views\Plugin\ViewsPluginManager are: entity_browser, entity_reference_revisions, rest_export, page, attachment, feed, entity_reference, block, default, embed"

...because of "csv_serialization (missing)". Downloaded, renamed, upload as per #25 above. Ludwig doesn't acknowledge Uninstalled/Installed library.

Log also showing this error, which I'm sure is related...

" Error: Call to a member function getPluginDefinition() on null in Drupal\views_ui\ViewListBuilder->getDisplaysList() (line 261 of /.../public_html/core/modules/views_ui/src/ViewListBuilder.php)"

UPDATE 3/31/20, 9 am PST

I pulled the Views Data Export rows out of the database, so I can access the Views module and no longer get the call to member function error above. So that's good.

Why did I have to reinstall VDE and its library csv_serialization upon core update, you ask? Full disclosure: I must have uploaded these items to the Core/Modules instead of /Modules dir in the first place. I know. Rookie mistake. Is that possible, though - would Ludwig acknowledge misplaced modules and provide the link to the libraries?

Anyways, I've removed (UI > Extend/Uninstall, Purge Configurations for VDE + removed dirs via cPanel FileManager) and reinstalled multiple times. Ludwig does not acknowledge when VDE is installed/reinstalled (even with post install cache flush). I've created a dir structure as per #25 above (csv_serialization/lib/league-csv/8.2.2) and uploaded it to the /modules dir. Flush all caches. Still showing "csv_serialization(missing)."

I also reinstalled Ludwig, just to be sure. No effect.

I haven't had my ass kicked like this here for a while. Guess it was time.

Any help would be appreciated.

brussam’s picture

I am on Drupal 8.8.5 and was trying to install Views Data Export. The CSV Serialization has a problem with League/CSV until I used:
composer require league/csv:^8.0
because the current versions were 9.x. But I kept getting the need for league/csv library to enable the CSV Serialization module.

I can see that a root/vendor/league/csv folder was created so that part of Composer worked, but no league/csv library.

I finally installed Ludwig and followed the directions and got the library installed in root/web/module/contrib/csv_serialization/lib.

The preferred use of Composer was a hardship as the shared server I use for a host could not supply enough memory for Composer to run. So I bit the bullet and created a LAMP server is a VM partiton of a space laptop with 16GB of memory. Now I could install my modules using Composer. Until today.

I see some great work by the people supporting Drupal and it would be great is the issues of things that don't install with Composer are fixed. And then find a way to not need a development server to use Composer.

oscar.gomez.alcaniz’s picture

My company's Drupal infrastructure doesn't allow me to use Composer so I had no choice but to apply workaround #19.

It would be nice to offer an alternative install which doesn't require Composer. Although it's the recommended way to install certain modules these days, it's not something that will be available on all Drupal infrastructures.

toxiclung’s picture

composer doesnt work for me, #19 and #25 solve it for me

PhilippJor’s picture

Issue tags: +Drupal9 compatibility

It works for me in drupal 9.2 only with #25 and Modul Ludwig. A composer does not work, because structure is not oriented to drupal9. I got

drupal.org/9/packages.json file could not be downloaded

But in Drupal9 only JSON, XML and CSV works. I needed DOC, but that is actually in progress. In Drupal9 I do not findy any alternatives at the moment. :-(

devad’s picture

This is a closely related 8.x-2.x issue for those who want to manage library with Ludwig. Please review the provided patch and help to move this issue to RTBC.

#3198535: The FILES type libraries are not supported by Ludwig automatically.

ladybug_3777’s picture

Status: Closed (works as designed) » Active

***EDIT****
Opening a new issue, I think my error message is slightly different and has something else going on.
*******

I was on Drupal 9.1.10 I was receiving a similar error even after trying all the suggestions in all the comments above (except using Ludwig since I use composer and installed all modules and core using it)

I upgraded core to 9.2 hoping that might resolve the issue but it did not.

I'm reopening this as "Active" because it's still an issue that has not been resolved and (at least for D9). I don't want to have to add an alternative to composer if I don't have to so I'm trying to avoid using ludwig at the moment.

Current versions installed:
Drupal 9.2
csv_serialization 2.0.0
league/csv 9.1

My error occurs after creating a data export view and trying to view the export.

Error details:

he website encountered an unexpected error. Please try again later.
Error: Class "League\Csv\Writer" not found in Drupal\csv_serialization\Encoder\CsvEncoder->encode() (line 150 of modules/contrib/csv_serialization/src/Encoder/CsvEncoder.php).
Drupal\csv_serialization\Encoder\CsvEncoder->encode(Array, 'csv', Array) (Line: 40)
Symfony\Component\Serializer\Encoder\ChainEncoder->encode(Array, 'csv', Array) (Line: 306)
Symfony\Component\Serializer\Serializer->encode(Array, 'csv', Array) (Line: 129)
Symfony\Component\Serializer\Serializer->serialize(Array, 'csv') (Line: 77)
Drupal\serialization\EventSubscriber\DefaultExceptionSubscriber->on4xx(Object) (Line: 112)
Drupal\Core\EventSubscriber\HttpExceptionSubscriberBase->onException(Object, 'kernel.exception', Object)
call_user_func(Array, Object, 'kernel.exception', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.exception') (Line: 219)
Symfony\Component\HttpKernel\HttpKernel->handleThrowable(Object, Object, 1) (Line: 91)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 716)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

devad’s picture

Status: Active » Closed (works as designed)

Reverting status as per #43 edit.

VisionSSC’s picture

Component: Documentation » Code
Assigned: Unassigned » VisionSSC
Priority: Normal » Major
Status: Closed (works as designed) » Active

Please help me this issue

devad’s picture

Assigned: VisionSSC » Unassigned
Priority: Major » Normal
Status: Active » Closed (works as designed)

@VisionSSC

Please do not change this issue settings.

Read carefully through this issue posts and read the project's readme.md file and follow installation instructions and you will find solution to your problem.

If not, Please use Stack Exchange to post your how-to questions: https://drupal.stackexchange.com/