Ionic 2 unmanageble directory structure

I installed the latest node and npm, started a new ionic 2 app but I got the following error:
**
Installing npm packages…
Error with start undefined
Error Initializing app: There was an error with the spawned command: npminstall
There was an error with the spawned command: npminstall
**
trying to run the ionic serve command, I got the following message:
"Cannot find module ‘process-nextick-args’ "
By the way, it seems that right now the node_modules directory is flat.

I just want to add that there are quite a few breaking changes in Node6.

I installed the ‘process-nextick-args’ package but then I got another error "Cannot find module ionic-gulp-sass-build"
Tried to install it but after installation I got the same error again.

I was struggling with this too. Windows was not able to delete folders containing ionic apps.
Problem is that paths with nested node_modules are too long for windows to handle.

I found some solutions on the net and ended up making this little bat-file for delete folders containing files with too long names.

Use with care :slight_smile:

Usage: delete_long_names FolderName

delete_long_names.bat:

@echo off

echo **
echo ** Folder: %1 
echo **
echo ** USE WITH CARE
choice /C YN /M "Are you sure to delete?"

if %ERRORLEVEL% NEQ 1 (
    goto ABORT
)

echo Deleting %1...

mkdir empty_dir_1234_OO1X_987
robocopy empty_dir_1234_OO1X_987 %1 /s /mir
rmdir empty_dir_1234_OO1X_987
rmdir %1

exit /b

:EMPTY
echo "Missing input (folder name) Folder not found."
exit /b

:ABORT
echo "Aborting..."

Well, my first aim was to try to work with ionic 2!
Long file names is a side effect!

Funny thing is that after the updates that you proposed, I cannot use “ionic serve” because of the errors that I mentioned. Before the updates, at least I was able to run the application with the “ionic serve” command even with the long file names problem!

This is an unfortunate side effect of developing on Windows, they have this arbitrary limit (long ago it wasn’t arbitrary, but now it makes no sense).

Quick and dirty answer, download Cygwin so you can use a Unix shell in Windows. This will also let you delete those paths.

Windows announced in future version it will include a bash shell as to be more attractive to developers, but in the mean time Cygwin works.

Long Path Tool help me a lot when i have an issue like file deleting or renaming the file. Also good to use if file name and file extension is too long.

@gnout It seems that node-sass is not compatible with Node v6 (check out the linked post for details):

Could you run the start command with --verbose so we can see what the output from npm is? Hopefully this will give some insight as to what’s going wrong.

ionic start myapp --v2 --ts --verbose

Thanks!

EDIT: or if you prefer, delete the node_modules directory in your app and run npm install from your project root

1 Like

I’m away for a few days. I will be back mid next week. I will try the solution that you proposed and keep you posted.

Hi Gnout,
I have Windows 10 and I’ve never seen this issue in my computer or ionic workspace. I also keep up-to-date versions of all required software. However, I will admit I haven’t used ionic in like two months due to learning Game Development.

I’m sure you’ll find a workaround.

Regards,
Edwin B.
Neonic, Inc. CEO

I was having these problems with Windows and long file names etc however installing the latest npm fixed the issue because version 3 onwards I believe (and as Mike Hartington has also commented) creates a flat dependency tree structure for node modules.

Regardless if you have a recent version of Node, do this:

npm install -g npm

Note that npm is updated more frequently than Node, so the latest Node version may not necessarily have the latest npm version.

The latest npm version at the time of writing is 3.8.8.

1 Like

Finally! It worked! Funny thing is that I didn’t do anything different
node version: 6.0.0
npm version: 3.8.7
I executed the commands
ionic start myapp –v2
cd myapp
ionic serve
and I got the application running on Chrome! No errors!
The node_modules directory contains 505 directories! Is that normal?
Thank you for the support.
By the way, any news for Ionic 2 Visual Studio Templates?
There is a great VS template for Ionic 1, are you planning to have something similar for Ionic 2?

I ran into similar issues with my ionic projects and I resolved all of them with the Windows built-in RoboCopy (“Robust File Copy”) program.

First, to delete a folder with long path names, create a batch files with these contents (say it’s called delfolder.bat):

@echo off
REM from here: http://kb.ischool.uw.edu/use-robocopy-to-delete-filesfolders-with-long-filenames/
if {%1}=={} @echo Syntax: DelFolder FolderPath&goto :EOF
if not exist %1 @echo Syntax: DelFolder FolderPath – %1 NOT found.&goto :EOF
setlocal
set folder=%1
set MT=“%TEMP%\DelFolder_%RANDOM%”
MD %MT%
RoboCopy %MT% %folder% /MIR
RD /S /Q %MT%
RD /S /Q %folder%
endlocal

and then run

delfolder [your-folder-name]

RoboCopy can also be used to copy folders with long pathnames(just like XCOPY); I recommend you review all its options.

I struggled with this too. I found out that 7-zip does delete a long file structure :sunglasses:. No hassle with scripts.

Using the latest version of npm for future projects should prevent the need for any external software or scripts to copy/move/delete such projects. See my previous post.

Hi, I just ran into the same problem. I wanted to copy my project folder and then it said,that the file names are too long. Never have seen this before.
I updated node and npm nad also installed a new ionic project, but the error is still there.
Are there any other ideas how to manage this?

Thank you!

node: 6.9.1
npm: 3.10.9

Hi Basti
There is a new Template package for Visual Studio 2015 and Ionic 2. You can find it here.
I used it and it worked fine for me. Try it, maybe this will solve your problem.
It produce a huge project (~200MB)

D:\REPO_XXXXXXXX\test\android\node_modules\gulp-sass\node_modules\node-sass\node_modules\sass-graph\node_modules\yargs\node_modules\read-pkg-up\node_modules\read-pkg\node_modules\load-json-file\node_modules\parse-json\node_modules\error-ex\node_modules

Ionic v2.2.1
NPM v2.15.1

Suggestions to use Cygwin and other tools are work-arounds and not a structural solution. Its a big pain to delete a project! Is this being looked at?

Regards,

SG